i have a person object and need to store it as byte[] and again retrieve that byte[] and convert to person object and BinaryFormatter is not availabe in silverlight
views:
255answers:
2
+1
A:
Use the serialized class to convert the object into a byte via using a MemoryStream
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
....
byte[] bPersonInfo = null;
using (MemoryStream mStream = new MemoryStream())
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, personInfo);
bPersonInfo = mStream.ToArray();
}
....
// Do what you have to do with bPersonInfo which is a byte Array...
// To Convert it back
PersonInfo pInfo = null;
using (MemoryStream mStream = new MemoryStream(bPersonInfo)){
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new BinaryFormatter();
pInfo = (PersonInfo)bf.DeSerialize(mStream);
}
// Now pInfo is a PersonInfo object.
Hope this helps, Best regards, Tom.
tommieb75
2010-02-17 14:05:11
Thanks Tom, The BinaryFormatter is not available in SilverLIght
taher chhabrawala
2010-02-19 12:58:51