mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 22:36:20 +00:00
Update Utils.cs
fix BinaryFormatter usage risk and change to System.Text.Json standard library.
This commit is contained in:
parent
bc957fea71
commit
f61f1552f9
1 changed files with 10 additions and 10 deletions
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue