mirror of
https://github.com/2dust/v2rayN.git
synced 2025-12-16 20:02:43 +00:00
Update JsonUtils.cs
This commit is contained in:
parent
c63d4e83f9
commit
86eb8297dd
1 changed files with 9 additions and 5 deletions
|
|
@ -35,9 +35,13 @@ public class JsonUtils
|
|||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static T DeepCopy<T>(T obj)
|
||||
public static T? DeepCopy<T>(T? obj)
|
||||
{
|
||||
return Deserialize<T>(Serialize(obj, false))!;
|
||||
if (obj is null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
return Deserialize<T>(Serialize(obj, false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -67,7 +71,7 @@ public class JsonUtils
|
|||
/// </summary>
|
||||
/// <param name="strJson"></param>
|
||||
/// <returns></returns>
|
||||
public static JsonNode? ParseJson(string strJson)
|
||||
public static JsonNode? ParseJson(string? strJson)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -116,7 +120,7 @@ public class JsonUtils
|
|||
/// <param name="obj"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public static string Serialize(object? obj, JsonSerializerOptions options)
|
||||
public static string Serialize(object? obj, JsonSerializerOptions? options)
|
||||
{
|
||||
var result = string.Empty;
|
||||
try
|
||||
|
|
@ -125,7 +129,7 @@ public class JsonUtils
|
|||
{
|
||||
return result;
|
||||
}
|
||||
result = JsonSerializer.Serialize(obj, options);
|
||||
result = JsonSerializer.Serialize(obj, options ?? _defaultSerializeOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue