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?
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With