public static object DeserializeType(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);
            BinaryReader br = new BinaryReader(ms);

            br.BaseStream.Position = br.BaseStream.Length - 5; // 1 byte + 1 int
            AdHocDesktop_SerializeType type = (AdHocDesktop_SerializeType)br.ReadInt32();

            object result = null;

            switch (type)
            {
            case AdHocDesktop_SerializeType.AdHocDesktop_TcpObject:
                result = new AdHocDesktop_TcpObject();
                ((IAdHocDesktop_Serializable)result).Deserialize(data);
                break;
            }

            return(result);
        }
 public static void SerializeType(BinaryWriter bw, AdHocDesktop_SerializeType data)
 {
     bw.Write(((int)data));
     bw.Write(((byte)255));
 }