Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the deserialize equivalent of ISerializable.GetObjectData?

I'm writing a custom serializer, and I've just finished implementing the portion for handling ISerializable.GetObjectData. But when I go to deserialize the information and re-apply it to the graph, I don't see an equivalent function for Set-ObjectData.

How do I go about re-applying SerializationInfo data to the graph?

like image 505
sircodesalot Avatar asked May 03 '13 16:05

sircodesalot


1 Answers

Implement the special deserialization constructor as described in the MSDN Library documentation for ISerializable:

The ISerializable interface implies a constructor with the signature constructor (SerializationInfo information, StreamingContext context). At deserialization time, the current constructor is called only after the data in the SerializationInfo has been deserialized by the formatter. In general, this constructor should be protected if the class is not sealed.

For example:

protected Widget(SerializationInfo info, StreamingContext context)
{
    // Perform your deserialization here...
    this.SerialNumber = (string)info.GetValue("SerialNumber", typeof(string));
}
like image 168
Michael Liu Avatar answered Nov 20 '22 17:11

Michael Liu