Examples

Simple examples

Example with a file name

var data = new Hashtable(); data.Add(0, 1);

using (var s = new UniversalSerializer("serialized.uniser"))
{
  s.Serialize(data);
  var data2 = s.Deserialize<Hashtable>();
}

That is that simple!

Example with a stream

var data = new Hashtable(); data.Add(0, 1);

using (var ms = new MemoryStream())
{ 
  var s = new UniversalSerializer(ms); 
  s.Serialize(data);  
  var data2 = s.Deserialize<Hashtable>();
}

Example serializing to XML

var data = new Hashtable(); data.Add(0, 1);

using (var ser = new UniversalSerializer("serialized.uniser.xml", SerializerFormatters.XmlSerializationFormatter))
{
  ser.Serialize(data);
  var deserialized = ser.Deserialize<Hashtable>();
}

Example serializing to JSON

var data = new Hashtable(); data.Add(0, 1);

using (var ser = new UniversalSerializer("serialized.uniser.json", SerializerFormatters.JSONSerializationFormatter))
{
  ser.Serialize(data);
  var deserialized = ser.Deserialize<Hashtable>();
}

Example for WPF

There is a specialized DLL for WPF, that manages more WPF types:

var data = new System.Windows.Window() { Title = "Hello!" };

using (var s = new UniversalSerializerWPF("serialized WPF.uniser"))
{
  s.Serialize(data);
  var data2 = s.Deserialize<System.Windows.Window>();
}

Example for Windows Forms

There is a specialized DLL for Windows Forms, that manages more Windows Forms types:

var data = new System.Windows.Forms.Form() { Text = "Hello!" };

using (var s = new UniversalSerializerWinForm("serialized WinForm.uniser"))
{
  s.Serialize(data);
  var data2 = s.Deserialize<System.Windows.Forms.Form>();
}