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. 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. A custom implementation of the class constructor must also be provided. You have to first reproduce at least what built-in formatters do during serialization. The code in Listing 39.2 shows how to provide custom serialization for the Person class.

LISTING 39.2 Providing Custom Serialization

Imports System.Runtime.Serialization ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.