This sample demonstrates the runtimeΓÇÖs ability to serialize an object graph in memory to a stream. This sample can use either the SoapFormatter or the BinaryFormatter for serialization. A linked list, filled with data, is serialized or deserialized to/from a file stream. In either case the list is displayed so that you can see the results. The linked list is of type LinkedList which is a type defined by this sample.
<b>Serialize.exe</b> accepts command line parameters indicating which test you would like to execute.
</step>
<step>
To serialize a 10-node list to a file name Test.xml using the soap formatter you might enter the following on the command line:<p class ="FixedText">Serialize.exe -sx Test.xml 10</p>
</step>
<step>
To deserialize the Test.xml file from the previous example enter the following on the command line:<p class ="FixedText">Serialize.exe -dx Test.xml</p>
</step>
<step>
In the previous two examples, the <b>x</b> in the command line switch indicates that you want XML Soap serialization. You can use <b>b</b> in its place to use binary serialization.
</step>
<step>
If you wish to try serialization with a very large number of nodes, you might want to redirect the console output to a file.
<example>
Serialize.exe -sb Test.bin 10000 >somefile.txt
</example>
</step>
</runsteps>
<technologies>
<technology name = "Runtime Serialization" keyword="T">
<class name = "IFormatter" keyword="T">
The sample uses a reference to this interface type to refer to either a BinaryFormatter or a SoapFormatter object.
</class>
<class name = "BinaryFormatter" keyword="T">
Used to serialize a linked list to a stream in a binary format. The binary formatter uses a format that only the BinaryFormatter type understands. However, the data is concise.
</class>
<class name = "SoapFormatter" keyword="T">
Used to serialize a linked list to a stream in the SOAP format. SOAP is a standard format.
</class>
</technology>
<technology name = "Stream I/O" keyword="T">
<class name = "Stream" keyword="T">
The sample uses the Stream base class to serialize and deserialize. The specific stream type used in this sample is the FileStream type. However, serialization can be used with any type derived from Stream.
</class>
<class name = "File" keyword="T">
The sample uses this type to create FileStream objects for reading and creating files on disk.
</class>
<class name = "FileStream" keyword="T">
The sample uses this Stream-derived type to serialize and deserialize linked lists.