Custom Serialization
In most cases the .NET built-in serialization engine is good enough. But if it does not meet your particular needs, you can override the serialization process with custom serialization. Basically this means implementing the ISerializable interface that requires the implementation of the GetObjectData method. Such a method is important because it is invoked during serialization. Moreover a custom implementation of the class constructor must be provided. Basically you have to first reproduce at least what built-in formatters do during serialization. Code in Listing 43.2 shows how to provide custom serialization for the Person class.
Listing 43.2 Providing Custom Serialization
The GetObjectData method is basically invoked ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access