修复了已知的bug

This commit is contained in:
fengjiayi
2025-09-04 10:39:57 +08:00
parent f9ab920939
commit 51c268baad
28 changed files with 1099 additions and 108 deletions

View File

@@ -4,9 +4,25 @@ namespace Serein.Extend.NewtonsoftJson
{
public static class NewtonsoftJsonExtend
{
/// <summary>
/// 对象转 Json 文本
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string ToJsonText(this object data)
{
return JsonHelper.Serialize(data);
}
/// <summary>
/// Json 文本转对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonText"></param>
/// <returns></returns>
public static T ToJsonObject<T>(this string jsonText) where T : class
{
return JsonHelper.Deserialize<T>(jsonText);
}
}
}

View File

@@ -7,11 +7,6 @@ using System.Diagnostics.CodeAnalysis;
namespace Serein.Extend.NewtonsoftJson
{
public enum ProviderType
{
Default = 0,
Web = 1,
}
/// <summary>
/// 基于Newtonsoft.Json的IJsonProvider实现
/// </summary>
@@ -20,39 +15,23 @@ namespace Serein.Extend.NewtonsoftJson
private JsonSerializerSettings? settings;
/// <summary>
/// 基于Newtonsoft.Json的JSON门户实现
/// 基于Newtonsoft.Json的JSON门户实现默认首字母小写、忽略null
/// </summary>
public NewtonsoftJsonProvider()
{
}
/// <summary>
/// 基于Newtonsoft.Json的JSON门户实现
/// </summary>
/// <param name="jsonType"></param>
public NewtonsoftJsonProvider(ProviderType jsonType)
{
settings = jsonType switch
{
ProviderType.Web => new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(), // 控制首字母小写
NullValueHandling = NullValueHandling.Ignore // 可选:忽略 null
},
_ => new JsonSerializerSettings
{
},
};
}
public NewtonsoftJsonProvider(JsonSerializerSettings settings)
{
settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(), // 控制首字母小写
NullValueHandling = NullValueHandling.Ignore // 可选:忽略 null
};
}
/// <summary>
/// 使用自定义的序列化设置
/// </summary>
/// <param name="settings"></param>
public NewtonsoftJsonProvider(JsonSerializerSettings settings)
{
this.settings = settings;
}

View File

@@ -8,7 +8,7 @@
<BaseOutputPath>..\.\.Output</BaseOutputPath>
<Title>为 SereinFlow 提供的 JSON 扩展</Title>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Description>通过 NewtonsoftJson 实现JSON门户扩展用于解决 Serein.Proto.* 项目下需要 JSON 序列化与反序列化的场景</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>