My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Usage  
A Basic guide to how to use the serializer
Featured
Updated Feb 4, 2010 by elliott....@gmail.com

Usage:

To serialize and deserialize objects, first you must get an instance of a serializer.

  Serializer serializer = Serializer.GetSerializer(typeof(MyClass));

Then to serialize use the Serialize method, passing in your object to serialize. You can either serialize to a string, or write the serialization to a TextWriter if you're serializing to a file or socket perhaps.

Serialize to String:

   MyClass myClass = new MyClass();
   ... // set myClass properties

   string result = serializer.Serialize(myClass);

Serialize to TextWriter:

   MyClass myClass = new MyClass();
   ... // set myClass properties
   
   TextWriter writer = new TextWriter(new FileStream("somefile.jsx", FileMode.Create));
   serializer.Serialize(myClass, writer);
   writer.Close();

Then to Deserialize, just reverse the process calling the Deserialize method.

Deserialize from String:

   string result = ... Populate the string with previously serialized content
   MyClass myClass = (MyClass) serializer.Deserialize(result);

Deserialize from TextReader:

   TextReader reader = new TextReader(new FileStream("somefile.jsx", FileMode.Open));
   MyClass myClass = (Myclass) serializer.Deserialize(reader);
   reader.Close();
Comment by slion2...@gmail.com, May 10, 2008

Simple and fantastic! Thanks

Comment by vespe...@gmail.com, Jan 29, 2012

good stuff


Sign in to add a comment
Powered by Google Project Hosting