Section 1
Serialize or deserialize an object or an object graph by using runtime serialization techniques. (Refer System.Runtime.Serialization namespace)
- Serialization interfaces
- Serilization attributes
- SerializationEntry structure and SerializationInfo class
- ObjectManager class
- Formatter class, FormatterConverter class, and FormatterServices class
- StreamingContext structure
Summary
Serialization Interfaces include the ISerializable interface which allows you to control the serialization process. In order to implement ISerializable you must provide a GetObjectData method as well as a specialized constructor that accepts two parameters: an instance of SerializationInfo, and an instance of StreamingContext.
Other Seriailization Interfaces include (This list comes from the list of Interfaces in the System.Runtime.Serialization Namespace as indicated on msdn2)
IDeserializationCallback - Indicates that a class is to be notified when deserialization of the entire object graph has been completed.
IFormatter - Provides functionality for formatting serialized objects.
IFormatterConverter -Provides the connection between an instance of SerializationInfo and the formatter-provided class best suited to parse the data inside the SerializationInfo.
IObjectReference - Indicates that the current interface implementer is a reference to another object.
ISerializationSurrogate - Implements a serialization surrogate selector that allows one object to perform serialization and deserialization of another.
ISurrogateSelector - Indicates a serialization surrogate selector class.
The following list of XmlAttributes came from the first link in the resources section:
XmlRoot – Controls the XML root. ElementName, namespace..
XmlElementAttribute – Serialize the field/property as an element in the XML document.
XmlAttributeAttribute – Aside from being the victim of strict naming conventions, it tells the XML serializer to serialize field/prop as an attribute in the XML document
XmlIgnoreAttribute – Tells the XML Serializer to omit the field/property.
XmlEnumAttribute – Controls the name of an enumeration member (Not the enum name, a member of the enum)
XmlTextAttribute - Tells the XML Serializer that the member contains raw XML text.
XmlTypeAttribute - Controls the XML Schema (XSD) that is generated by the XmlSerializer. It is used to specify other namespaces and types when serializing.
XmlIncludeAttribute - Allows the XmlSerializer to recognize a type when it serializes or deserializes an object. Used when deserializing custom types.
XmlChoiceIdentifierAttribute - Tells the XML Serializer that the type should be XSI:Choice. It is used in conjunction with an enum field/prop in the class to tell the serializer where to get its info from.
XmlArrayAttribute Class - Specifies that the XmlSerializer must serialize a particular class member as an array of XML elements.
XmlArrayItemAttribute – Specifies the types that are contained in an XmlArray. This is used when you are serializing polymorphic classes.
XmlAnyAttributeAttribute – Any attributes that are not matched up during deserialization is placed in the field decorated with this attribute. Field must be an array of XmlAttribute.
XmlAnyElementAttribute – Any elements that are not matched up during deserialization is placed in the field decorated with this attribute. Field must be an array of XmlElement.
XmlNamespaceDeclarationsAttribute – Decorates a field that returns XmlSerializerNamespaces. That field will be use to get namespace prefixes during serialization.
XmlSchemaProviderAttribute – "When applied to a type, stores the name of a static method of the type that returns an XML schema and a XmlQualifiedName that controls the serialization of the type. " Used by WSDL.exe to return the schema for the class. Target class must implement IXmlSerializable. New to 2.0.
XmlSerializerAssemblyAttribute – Specifies the name of an assembly that the Xml Serializer can use. If specified, the Xml Serializer doesn’t need to create a temporary assembly. New to 2.0
XmlSerializerVersionAttribute – Signifies that the code was generated by the serialization infrastructure and can be reused for increased performance, when this attribute is applied to an assembly. I’m not sure I should use this attribute. I think this is used by code produced by sgen.
The SerializationEntry Structure encapsulates the name, type and value of the object being serialized.
The ObjectManager Class is used by the formatter to keep track of object during deserialization. It checks and handles objects for forward references (a reference to an object that has not been deserialized) and also raises events.
The Formatter Class is used to determine the base abstract class for Formatter Implementation that format the data for Serialization. Two Implementations of this class include the BinaryFormatter and SOAPFormatter.
The FormatterConverter Class is used to Convert Objects to .Net CLR value types. It containes methods like ToString, ToInt, ToByte, etc.
The FormatterServices Class is used to give information to the formatter, including retrieving a list of the serializable members in their object, as well as their types and values.
The StreamingContext Structure encapsulates the source and destination of a Serialized stream. During serialization,the state property exposes the destination of the transmitted data. During deserialization, the source of the data.
Other Resources & Links:
ISerialization Interface
http://msdn2.microsoft.com/wf4375ks(en-US,VS.80).aspx
System.Runtime.Serialization Namespace
http://msdn2.microsoft.com/system.runtime.serialization.aspx
What Did you learn Today (List of Xml Attributes)
http://blog.denoncourtassociates.com/default,date,2006-02-01.aspx
SerializationEntry Structure
http://msdn2.microsoft.com/wb7s1ykw(en-US,VS.80).aspx
ObjectManager Class
http://msdn2.microsoft.com/dd3w47bb(en-US,VS.80).aspx
.Net Serialization
http://www.codeguru.com/columns/DotNet/article.php/c6595/
FormatterConverter Class
http://msdn2.microsoft.com/cb3z6hzc(en-US,VS.80).aspx
StreamingContext Structure
http://msdn2.microsoft.com/t16abws5(en-US,VS.80).aspx