Monday, June 22, 2009

Chapter 5-Lesson 1

  • Converting Object information into another format is called Serialization.
  • System.Runtime.Serialization namespace is required
  • Items copied to clipboard, Remoting and Web Services are good examples of Serialization
  • For Binary Serialization, we use System.Runtime.Serialization.Formatters.Binary namespace BinaryFormatter class.
  • The terms 'Backward Reference' and 'Forward Reference' are used during Deserialization process when an object being Deserialized refers to another object.
  • If the referenced object is already Deserialized, the Formatter treats it a Backward Reference and completes the reference immediatly.
  • However, if the referenced object is not Deserialized yet, it is treated as a Forward Reference and the Formatter registers a fix-up with the ObjectManager which would later on complete the reference.
  • Serializable attribute allows a custom class object to be serialized by a Formatter. All members (including private ones) are serialized.
  • NonSerialized attribute before any class member would omit it from (De)Serialization process.
  • IDeserializationCallback.OnDeserialization( ) method may then be used to initialize objects which were omitted during (De)Serialization.
  • In situations where after serialization, one adds additional members to a class, deserialization may fail because serialized object would not contain info about that additional field. Therefore, if a class has previously been used for Serialization, its always good to use OptionalField attribute to newly added members for sake of Version Compatibility.
  • If members were removed from a class after some objects were serialized, .NET 2.0 would NOT throw an exception while deserializing (since there would be more info available than requested for deserialization). Older versions on .NET did.
  • If object is serialized so that it would later be read by ONLY .NET based applications, use of BinaryFormatter is preferrable. Otherwise use SOAPFormatter.
  • Using SOAPFormatter requires the project to have a reference to System.Runtime.Serialization.Formatters.Soap.dll which is not included by default in .NET 2.0
  • Use BinaryFormatter for best efficiency and SOAPFormatter for portability.
  • SoapIgnore attribute is used for public members of class which we do not wish to serialized to XML.

No comments:

Post a Comment