public static string SerializeObject(object o)
{
if (!o.GetType().IsSerializable)
{
return null;
}
using (MemoryStream stream = new MemoryStream())
{
new BinaryFormatter().Serialize(stream, o);
return Convert.ToBase64String(stream.ToArray());
}
}
public static object DeserializeObject(string str)
{
byte[] bytes = Convert.FromBase64String(str);
using (MemoryStream stream = new MemoryStream(bytes))
{
return new BinaryFormatter().Deserialize(stream);
}
}
Hope this helps