plcsharp/PLCSharpWpf/Core/Tools/JsonOptions.cs
2026-08-04 11:52:30 +08:00

33 lines
1.1 KiB
C#

#nullable enable
using System.Text.Json;
using System.Text.Json.Serialization;
namespace PLCSharp.Core.Tools
{
/// <summary>
/// 全局共享的 System.Text.Json 序列化选项。
/// </summary>
public static class JsonOptions
{
/// <summary>
/// 默认选项:属性名大小写不敏感(用于 EF Core 列序列化 / 反序列化);
/// 允许 NaN / Infinity 等命名浮点字面量,避免局部变量表中的非法值导致序列化崩溃。
/// </summary>
public static JsonSerializerOptions Default { get; } = new()
{
PropertyNameCaseInsensitive = true,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
};
/// <summary>
/// 缩进输出选项(用于配置文件读写)。
/// </summary>
public static JsonSerializerOptions Indented { get; } = new()
{
PropertyNameCaseInsensitive = true,
WriteIndented = true,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
};
}
}