You will need to serialize to something: select binary or xml (for serializers by default) or write a special serialization code for serialization into another text form.
Once you have selected this, your serialization (usually) will invoke a stream that writes to some file.
So, with your code, if I were to use XML serialization:
var path = @"C:\Test\myserializationtest.xml"; using(FileStream fs = new FileStream(path, FileMode.Create)) { XmlSerializer xSer = new XmlSerializer(typeof(SomeClass)); xSer.Serialize(fs, serializableObject); }
Then for deserialization:
using(FileStream fs = new FileStream(path, FileMode.Open)) //double check that... { XmlSerializer _xSer = new XmlSerializer(typeof(SomeClass)); var myObject = _xSer.Deserialize(fs); }
NOTE. This code has not been compiled, let alone run - there may be some errors. In addition, this involves full serialization / deserialization. If you need individual behavior, you will need to do extra work.
AllenG May 24 '11 at 19:29 2011-05-24 19:29
source share