Tuesday, 6 November 2007

Chapter 5, lesson 3: Custom Serialization.

Custom Serialization - process of controlling the serialization/deserialization of a type.
use: serialization compatibility - ability to serialize/deserialize between versions of a type without breaking core functionality of type. (e.g. vers. n+1 needs to be able to deserialize objs of vers n).

Custom Serialization
  • override default serialization built-in to .NF - impl. ISerializable interface + apply Serializable attr to class.
  • when? 1) when value of member variable is invalid after deserialization, 2) when class to serialize is marked with Serializable attr. + has declarative or imperative security.
  • how impl. ISerializable interface? impl. GetObjectData() - for during serialization - special constructor - during deserialization. SerializationInfo obj - AddValue() - add variables to be serialized as name/value pairs.
  • respond to serialization events - to alter obj <> (de)serialization. Mthd must 1) accept StreamingContext object, 2) ret. void, 3) be decorated with attr. that you want to intercept.
  • StreamingContext structure - provides info re. the destination of a serialized object, toclasses that impl. ISerializable interface.

No comments: