Enjoy!
using (MemoryStream stream = new MemoryStream())
{
DataContractSerializer serializer = new DataContractSerializer(typeof(SomeClass));
serializer.WriteObject(stream, instanceOfSomeClass);
// Serialisation defaults to UTF8Encoding when used with a stream.
// See Simple Serialization at http://msdn.microsoft.com/en-us/library/ms731073.aspx
string data = Encoding.UTF8.GetString(stream.ToArray());
// Do something useful with the data.
}
No comments:
Post a Comment