Oxite Administrator (gravatar)

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.

Hosted by imgur.com

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. 

Hosted by imgur.com

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

Hosted by imgur.com

 

Shout it

0 Comments

Your Information
Mrs. Gravatar (gravatar)

<-- It's a gravatar

your comment