Basic Serialization Technology Sample
This sample demonstrates the common language 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 or 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, a type defined by this sample.
Review comments in the source code and build.proj files for more information on serialization.
Navigate to one of the language-specific subdirectories under the Technologies\Serialization\Runtime Serialization\Basic directory, using the command prompt.
Type msbuild SerializationCS.sln, msbuild SerializationJSL.sln or msbuild SerializationVB.sln, depending on your choice of programming language, at the command line.
Open File Explorer and navigate to one of the language-specific subdirectories for the sample.
Double-click the icon for the SerializationCS.sln, SerializationJSL.sln or SerializationVB.sln file, depending on your choice of programming language, to open the file in Visual Studio.
In the Build menu, select Build Solution.
The sample application will be built in the default \bin or \bin\Debug subdirectory.
Navigate to the directory containing the built executable.
Type Serialization.exe, along with the parameter values you desire, at the command line.
This sample builds a console application. You must launch it using the command prompt in order to view its output.
The sample application accepts command line parameters indicating which test you would like to execute. To serialize a 10-node list to a file named Test.xml using the SOAP formatter, use the parameters sx Test.xml 10.
Serialize.exe -sx Test.xml 10
To deserialize the Test.xml file from the previous example, use the parameters dx Test.xml.
Serialize.exe -dx Test.xml
In the two examples above, the "x" in the command line switch indicates that you want XML SOAP serialization. You can use "b" in its place to use binary serialization. If you wish to try serialization with a very large number of nodes, you might want to redirect the console output to a file.
Serialize.exe -sb Test.bin 10000 >somefile.txt
The following bullets briefly describe the classes and technologies used by this sample.
SoapFormatter Used to serialize a linked list to a stream in the SOAP format. SOAP is a standard format.
FileStream Used to serialize and deserialize linked lists.
Controlling XML Serialization Using Attributes
Introducing XML Serialization
XML and SOAP Serialization