A:增加全局JSON配置,并增加统一的序列化和反序列化
This commit is contained in:
1 parent
879dd0fc34
commit
96e60137b2
7 files changed
+141
-24
No files matched your search
@@ -36,4 +36,5 @@ public sealed class AppConfig
|
||||
/// 订阅字符串
|
||||
/// </summary>
|
||||
public static readonly string ApplicationInfoSubscribe= "ApplicationInfo";
|
||||
public static readonly string ProcessInfoSubscribe= "ProcessInfo";
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Common.Utils;
|
||||
|
||||
public static class JsonHelper
|
||||
{
|
||||
public static readonly JsonSerializerOptions CamelCaseOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
public static string ToJson<T>(T value) =>
|
||||
JsonSerializer.Serialize(value, CamelCaseOptions);
|
||||
|
||||
public static T? FromJson<T>(string json) =>
|
||||
JsonSerializer.Deserialize<T>(json, CamelCaseOptions);
|
||||
}
|
||||
Reference in new issue
Block a user