As far as I understand, the IDeserializationCallback interface and the OnDeserialized event can both be used when an object needs to perform some task after being deserialized.
IDeserializationCallback:
[Serializable]
public class Foo : IDeserializationCallback
{
public void OnDeserialization(object sender)
{
// initialize unserialized fields etc.
}
}
OnDeserialized event:
[Serializable]
public class Foo
{
[OnDeserialized]
public void OnDeserialized(StreamingContext context)
{
// initialize unserialized fields etc.
}
}
Are there any specific pros/cons or scenarios where you would choose one over the other?
Those two serve different purposes and cannot be used interchangeably. In most of the cases you probably will be better served by the interface.
Look here for some explanation: http://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/311b2b57-6b0a-49ed-aa96-84f69d51da0f
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