mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] TEngineServer
[+] TEngineServer
This commit is contained in:
29
Assets/GameScripts/DotNet/Core/Helper/JsonHelper.cs
Normal file
29
Assets/GameScripts/DotNet/Core/Helper/JsonHelper.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
#pragma warning disable CS8603
|
||||
|
||||
namespace TEngine.Core
|
||||
{
|
||||
public static class JsonHelper
|
||||
{
|
||||
public static string ToJson<T>(this T t)
|
||||
{
|
||||
return JsonConvert.SerializeObject(t);
|
||||
}
|
||||
|
||||
public static object Deserialize(this string json, Type type, bool reflection = true)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(json, type);
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(this string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
public static T Clone<T>(T t)
|
||||
{
|
||||
return t.ToJson().Deserialize<T>();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user