Revert "Clone using a MemoryStream"
This reverts commit 0da2fa0eabaac24ce360ee8d9506cc695b9e54ad.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Text.Json;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
namespace Core.Utils.Cloners;
|
||||
@@ -6,14 +5,15 @@ namespace Core.Utils.Cloners;
|
||||
[Injectable]
|
||||
public class JsonCloner : ICloner
|
||||
{
|
||||
protected JsonUtil _jsonUtil;
|
||||
|
||||
public JsonCloner(JsonUtil jsonUtil)
|
||||
{
|
||||
_jsonUtil = jsonUtil;
|
||||
}
|
||||
|
||||
public T? Clone<T>(T? obj)
|
||||
{
|
||||
using (MemoryStream ms = new())
|
||||
{
|
||||
JsonSerializer.Serialize(ms, obj);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return JsonSerializer.Deserialize<T>(ms);
|
||||
}
|
||||
return _jsonUtil.Deserialize<T>(_jsonUtil.Serialize(obj));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user