In the example given below, we will first serialize an object in memory and then deserializeit.
MemoryStream mStream = new MemoryStream();
-- Seriailize an Object
public void WriteObject(ClassTest objTest)
{
DataContractSerializer ser =
new DataContractSerializer(typeof(ClassTest ));
ser.WriteObject(mStream, objTest);
}
-- Deserialize the object in memory
public void ReadObject(ClassTest objTest)
{
DataContractSerializer ser = new DataContractSerializer(typeof(ClassTest ));
string result = Encoding.UTF8.GetString(mStream.GetBuffer(), 0, (int)mStream.Position);
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
EntityObj deserializedObj =
(EntityObj)ser.ReadObject(ms);
mStream.Close();
}
MemoryStream mStream = new MemoryStream();
-- Seriailize an Object
public void WriteObject(ClassTest objTest)
{
DataContractSerializer ser =
new DataContractSerializer(typeof(ClassTest ));
ser.WriteObject(mStream, objTest);
}
-- Deserialize the object in memory
public void ReadObject(ClassTest objTest)
{
DataContractSerializer ser = new DataContractSerializer(typeof(ClassTest ));
string result = Encoding.UTF8.GetString(mStream.GetBuffer(), 0, (int)mStream.Position);
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
EntityObj deserializedObj =
(EntityObj)ser.ReadObject(ms);
mStream.Close();
}
No comments:
Post a Comment