ISerializable Sample

Sample Overview

This sample illustrates how to use the ISerializable interface and XML serialization to customize the serialization of your own objects. This sample serializes objects that store reflection information from the mscorlib assembly namespace. Each object contains a property as the name of the item and a list of children as per the class in the mscorlib assembly. To demonstrate the customization possible with ISerializable, the string "(SAVED)" is appended to the namespace name to indicate that the values are not live. When the data is read back in, this tag could be modified or removed.

The sample starts by using reflection to create a TreeNode object that containing a list of TreeNode objects that represent types in the mscorlib assembly. This object is then serialized to disk. The user is then be prompted to continue deserializing the object from the XML file on disk.  The sample then outputs the results of the deserialized object to the console.

The sample generates a file named objectgraph.xml. This file contains the XML-serialized representation of the TreeNode object.

Sample Source and Build Output Locations

The sample source is found in sscli\samples\howto\serialization\iserializable. 

The source file is:

The build output location is %TARGETCOMPLUS%\samples\serialization.  The output file is an executable assembly named iserializable.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

  1. Run env.bat or source the env.csh or env.sh script files depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\serialization directory.
  3. Type the following command:

    clix  iserializable.exe


Copyright (c) 2002 Microsoft Corporation. All rights reserved.