Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

17. Serialization > Binary Serialization with ISerializable

Binary Serialization with ISerializable

Implementing ISerializable gives a type complete control over its binary serialization and deserialization.

Here’s the ISerializable interface definition:

public interface ISerializable
{
  void GetObjectData (SerializationInfo info, StreamingContext context);
}

GetObjectData fires upon serialization; its job is to populate the SerializationInfo object (a name-value dictionary) with data from all fields that you want serialized. Here’s how we would write a GetObjectData method that serializes two fields, called Name and DateOfBirth:

 public virtual void GetObjectData (SerializationInfo info,
                                     StreamingContext context)
  {
    info.AddValue ("Name", Name);
    info.AddValue ("DateOfBirth", DateOfBirth);
  }

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint