Update Utils.cs

fix BinaryFormatter usage risk and change to System.Text.Json standard library.
This commit is contained in:
Nima Zare 2023-05-23 09:27:11 +03:30 committed by GitHub
parent bc957fea71
commit f61f1552f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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