Skip to content

Commit

Permalink
FixExceptionInErrorjsonConvert
Browse files Browse the repository at this point in the history
  • Loading branch information
TaciturnJian committed Aug 31, 2023
1 parent 8389555 commit 7c937be
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions WolfBlades.BackEnd/ItemManager/TinyConverterExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Fleck;
using Newtonsoft.Json;

namespace WolfBlades.BackEnd.ItemManager;

Expand All @@ -9,10 +10,17 @@ public static string ToJsonString<T>(this T source, bool indented = false)
return JsonConvert.SerializeObject(source, indented ? Formatting.Indented : Formatting.None);
}

public static void EasyReadFrom<T>(this T item, string content) where T : IItem
public static void EasyReadFrom<T>(this T item, string content) where T : IItem, new()
{
var obj = JsonConvert.DeserializeObject<T>(content);
if (obj != null) item.ReadFrom(obj);
try
{
var obj = JsonConvert.DeserializeObject<T>(content);
if (obj != null) item.ReadFrom(obj);
}
catch (Exception ex)
{
FleckLog.Warn("", ex);
}
}

public static int ToID(this string? text)
Expand Down

0 comments on commit 7c937be

Please sign in to comment.