This commit is contained in:
Nima Zare 2023-05-23 09:28:17 +03:30 committed by GitHub
commit 9814c666f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -905,15 +905,15 @@ namespace v2rayN
/// <returns></returns>
public static T DeepCopy<T>(T obj)
{
object retval;
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
//序列化成流
bf.Serialize(ms, obj);
ms.Seek(0, SeekOrigin.Begin);
//反序列化成对象
retval = bf.Deserialize(ms);
return (T)retval;
using (MemoryStream stream = new MemoryStream())
{
// Serialize object to JSON
System.Text.Json.JsonSerializer.Serialize(stream, obj);
stream.Seek(0, SeekOrigin.Begin);
// Deserialize JSON to new object
return System.Text.Json.JsonSerializer.Deserialize<T>(stream);
}
}
/// <summary>
@ -1274,4 +1274,4 @@ namespace v2rayN
#endregion Windows API
}
}
}