Wassup Jose Weblog nonsense at its best!

5Jan/090

Deserialization Callback

Another trick I just picked up.

When serializing an object with the <Serializable> tag its possible to make specific properties non serializable <NonSerialized> to save space. For instance, you have a class ShoppingCart with a property named Total which is dynamically calculated by Price and QTY. The Total property doesn't need to be stored because we already serialized the values from which its calculated, Price and QTY. However, when the object is deserialized, Total will contain it default value. The .NET Framework accounts for this with the IDeserializationCallback interface. Implement this interface on your objects and implement the OnDeserialization method to instantiate any dynamically created values. Nice!

Filed under: Blog Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

 

No trackbacks yet.