<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">DataContractSerializer - on code</title>
  <icon>http://suhair.in/Content/icons/flame.ico</icon>
  <logo>http://suhair.in/Content/icons/flame.png</logo>
  <updated>2010-01-05T08:00:00</updated>
  <id>http://suhair.in/tags/datacontractserializer/atom</id>
  <link rel="alternate" type="text/html" hreflang="en" href="/tags/datacontractserializer/atom"/>
  <link rel="self" type="application/atom+xml" href="http://suhair.in/Tags/DataContractSerializer/ATOM"/>
  <generator uri="http://oxite.net" version="1.0">Oxite</generator>
  <entry>
    <title type="html">DataContract Serializer Essentials</title>
    <link rel="alternate" type="text/html" href="http://suhair.in/Blog/DataContract-Serializer-Essentials"/>
    <id>http://suhair.in/Blog/DataContract-Serializer-Essentials</id>
    <updated>2010-01-07T05:25:16.507</updated>
    <published>2010-01-05T08:00:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="csharp" />
    <category term="DataContractSerializer" />
    <content type="html" xml:lang="en">
      &lt;p&gt;
	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&amp;nbsp;&lt;span class=&quot;inlinecode&quot;&gt;System.Runtime.Serialization.dll&lt;/span&gt;. Decorate the Type and the members for the Type to be serialized as shown below.&lt;/p&gt;
&lt;p&gt;
	&lt;img alt=&quot;Hosted by imgur.com&quot; src=&quot;http://imgur.com/BhrdP.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;
	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.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
	&lt;img alt=&quot;Hosted by imgur.com&quot; src=&quot;http://imgur.com/aWT6D.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;
	The resulting XML file could be customized by passing the properties such as Name and Namespace to the DataContract and DataMember attributes.&lt;/p&gt;
&lt;p&gt;
	&lt;img alt=&quot;Hosted by imgur.com&quot; src=&quot;http://imgur.com/O0A7O.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;
	&amp;nbsp;&lt;/p&gt;
&lt;a rev=&quot;vote-for&quot; href=&quot;http://dotnetshoutout.com/DataContract-Serializer-Essentials-on-code&quot;&gt;&lt;img alt=&quot;Shout it&quot; src=&quot;http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fwww.suhair.in%2FBlog%2FDataContract-Serializer-Essentials&quot; style=&quot;border:0px&quot;/&gt;&lt;/a&gt;
    </content>
  </entry>
</feed>
