public class Formater
{
public static byte[] Serialize(Object _object)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
binaryFormatter.Serialize(ms, _object);
ms.Position = 0;
byte[] b;
b = new Byte[ms.Length];
ms.Read(b, 0, b.Length);
ms.Close();
return b;
}
public static Object Deserialize(byte[] serializes)
{
Object obj = new object();
if (serializes.Length == 0) return null;
try
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
ms.Write(serializes, 0, serializes.Length);
ms.Position = 0;
obj = binaryFormatter.Deserialize(ms);
ms.Close();
}
catch
{
obj = null;
}
return obj;
}
}