public static byte[] Serialize(TAbstractBase s) { var t = new TMemoryBuffer(); var p = new TBinaryProtocol(t); s.Write(p); return(t.GetBuffer()); }
public static T DeSerialize <T>(byte[] buf) where T : TAbstractBase { var trans = new TMemoryBuffer(buf); var p = new TBinaryProtocol(trans); if (typeof(TBase).IsAssignableFrom(typeof(T))) { var method = typeof(T).GetMethod("Read", BindingFlags.Instance | BindingFlags.Public); var t = Activator.CreateInstance <T>(); method.Invoke(t, new object[] { p }); return(t); } else { var method = typeof(T).GetMethod("Read", BindingFlags.Static | BindingFlags.Public); return((T)method.Invoke(null, new object[] { p })); } }