DataContract Serializer Essentials
DataContractSerializer could be used to serialize and deserialize instances of a type into an XML stream or document. The first step in the process is to prepare the type for the serialization. In order to apply the DataContract attributes we have to add reference to the assembly System.Runtime.Serialization.dll. Decorate the Type and the members for the Type to be serialized as shown below.

In addition to the implicit serialization, an instance of DataContractSerializer can be used to explicitly serialize the object by using an appropriate object to write the format (an instance of XmlWriter, fro example). The details are illustrated in the following picture.

The resulting XML file could be customized by passing the properties such as Name and Namespace to the DataContract and DataMember attributes.

0 Comments