Getting the sources
The sources are as usual available at GitHub (though but one should clone the solution repo if they want to build it).Installing it as a NuGet package
One can install it as the NuGet package Albite.Serialization.What can it serialiaze?
- Primitives
- Arrays
- Standard collections
- Classes
How can I use it?
Simply throw something at ObjectWriter.WriteObject() and than get it back using ObjectReader.ReadObject() .For example, serializing:
using (ObjectWriter writer = new ObjectWriter(stream))
{
writer.WriteObject(10);
writer.WriteObject(MyEnum.X);
writer.WriteObject("hello");
writer.WriteObject(new int[] { 10, 20 });
writer.WriteObject(new Stack<int>(new int[] { 100, 200 }));
writer.WriteObject(null);
writer.WriteObject(typeof(string));
}
Then, reading it back:
using (ObjectReader reader = new ObjectReader(stream))
{
int i = (int)reader.ReadObject();
MyEnum e = (MyEnum)reader.ReadObject();
string s = (string)reader.ReadObject();
int[] arr = (int[])reader.ReadObject();
Stack<int> st = (Stack<int>)reader.ReadObject();
object o = reader.ReadObject();
Type t = (Type)reader.ReadObject();
}
No comments:
Post a Comment