hehe =DeepClone(haha);
public static T DeepClone<T>(T obj)
{
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, obj); // obj 定义需要加上 [Serializable] ybhjx
ms.Position = 0;
return (T)formatter.Deserialize(ms);
}
}
public object memcpy( object des_obj1, object src_obj2)
{
byte[] aaa = StructToBytes(des_obj1);
IntPtr hPtr = Marshal.UnsafeAddrOfPinnedArrayElement(aaa, 0);//获取字节数组首地址
byte[] bbb = StructToBytes(src_obj2);
Marshal.Copy(bbb, 0, hPtr, bbb.Length);
des_obj1 = BytesToStuct(aaa, src_obj2.GetType());
return des_obj1;
}