Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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);
}