Web hosting contract - CHAPTER 17 UNDERSTANDING OBJECT SERIALIZATION 563 ISerializable
CHAPTER 17 UNDERSTANDING OBJECT SERIALIZATION 563 ISerializable and take matters into your own hands. However, as of .NET 2.0, new fields can now be explicitly marked with the [OptionalField] attribute (found within the System.Runtime.Serialization namespace): [Serializable] class UserPrefs { public ConsoleColor BackgroundColor; public ConsoleColor ForegroundColor; // New! [OptionalField] public int BeepFreq; [OptionalField] public string ConsoleTitle; public UserPrefs() { BeepFreq = 1000; ConsoleTitle = “My Console”; BackgroundColor = ConsoleColor.Black; ForegroundColor = ConsoleColor.Red; } } When a formatter deserializes an object that does not contain fields such optional fields, it will no longer throw a runtime exception. Rather, the data that is preserved is mapped back into the existing fields (BackgroundColor and ForegroundColor, in this case), while the remaining fields are simply assigned their default values. Note Understand that the use of [OptionalField] does not completely solve the process of versioning persisted objects. However, this attribute does provide a workaround for the most common headache of the versioning process (adding new field data). More elaborate versioning tasks may still require implementing the ISerializable interface. Source Code The VersionedObject project is included under the Chapter 17 subdirectory. Summary This chapter introduced the topic of object serialization services. As you have seen, the .NET platform makes use of an object graph to correctly account for the full set of related objects that are to be persisted to a stream. As long as each member in the object graph has been marked with the [Serializable] attribute, the data is persisted using your format of choice (binary, SOAP, or XML). You also learned that it is possible to customize the out-of-the-box serialization process using two possible approaches. First, you learned how to implement the ISerializable interface (and support a special private constructor) to become more involved with how formatters persist the supplied data. Next, you came to know a set of new attributes introduced with .NET 2.0, which simplifies the process of custom serialization. Just apply the [OnSerializing], [OnSerialized], [OnDeserializing], or [OnDeserialized] attribute on members taking a StreamingContext parameter, and the formatters will invoke them accordingly. The chapter wrapped up with an examination of a final attribute, [OptionalField], which can be used to gracefully version a serializable type.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.