static public byte[] ObjectToBytes(object obj)
{
byte[] bytes;
using (Stream stream = new MemoryStream())
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, obj);
bytes = new byte[stream.Length];
bytes = (stream as MemoryStream).ToArray();//.GetBuffer();
}
return bytes;
}