/* Simple C# serialization example for cs585 Demo program reads and writes a file of Items. Serialization must first write a file before it can read a file. To run demo open a command prompt window and cd to the executable's directory. Run the program. You must first run with the "false" argument since no file exists. SerializableDemo [] example: SerializableDemo filename false // create filename save items SerializableDemo filename // open filename read it and write it To compile demo Download files: Item.cs, Items.cs, and SerializableDemo.cs to a subdirectory. If you are using Visual Studio .NET create a C# empty project or console application project select Project | add exisiting item and add the 3 files to project if you have a console application you should remove form1.cs from project build the project If you are using the command line to compile and have Visual Studio .NET installed from start | programs | Visual Studio | tools select command prompt. In the command prompt console window cd to your directory. If you are using MS .NET Foundation Classes v1.1 in a command prompt console window cd to the your directory. Compile with the following line csc * cs Mike Barnes 11/15/03 */ using System; using System.Collections; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespace serializableDemo { public class SerializableDemo { Items items; public SerializableDemo() { items = new Items(); } // open a file of items to read into a vector // show the vector of items read // write the vector of items to a file public static void Main (string [] args) { String fileName = null; SerializableDemo demo = new SerializableDemo(); Console.WriteLine(); switch (args.Length) { case 1 : fileName = args[0]; demo.items.deSerialize(fileName); // sets new collection demo.items.show(); break; case 2 : fileName = args[0]; demo.items.show(); demo.items.serialize(fileName); break; default : Console.WriteLine("Usage:"); Console.WriteLine("SerializableDemo []"); Console.WriteLine(" examples:"); Console.Write(" SerializableDemo filename"); Console.WriteLine(" // open filename read and show items"); Console.Write(" SerializableDemo filename false"); Console.WriteLine(" // create filename and save items"); break; } } } }