14.1. Implement a Serializable Type

Problem

You need to implement a custom type that is serializable, allowing you to do the following:

  • Store instances of the type to persistent storage (for example, a file or a database).

  • Transmit instances of the type across a network.

  • Pass instances of the type "by value" across application domain boundaries.

Solution

For serialization of simple types, apply the attribute System.SerializableAttribute to the type declaration. For types that are more complex, or to control the content and structure of the serialized data, implement the interface System.Runtime.Serialization.ISerializable.

How It Works

Recipe 2-13 showed how to serialize and deserialize an object using the formatter classes provided with the .NET ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach 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.