mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 实现了YAML配置与JSON Schema的运行时校验能力 - 支持嵌套对象、对象数组、标量数组的递归校验 - 提供async和sync两种模式的schema文件加载解析 - 实现跨表引用的收集与校验机制 - 支持enum枚举值、引用约束和深层约束校验 - 添加了multipleOf、uniqueItems、contains等高级校验功能 - 实现了minProperties、maxProperties对象属性数量校验 - 提供详细的错误诊断信息和路径定位功能
30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
namespace GFramework.Game.Config;
|
|
|
|
/// <summary>
|
|
/// 提供可复用的 YAML 文本序列化入口,供生成配置绑定与宿主写回流程共享。
|
|
/// </summary>
|
|
public static class YamlConfigTextSerializer
|
|
{
|
|
private static readonly ISerializer Serializer = new SerializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.DisableAliases()
|
|
.ConfigureDefaultValuesHandling(DefaultValuesHandling.Preserve)
|
|
.Build();
|
|
|
|
/// <summary>
|
|
/// 将配置对象序列化为 YAML 文本。
|
|
/// </summary>
|
|
/// <typeparam name="TValue">配置对象类型。</typeparam>
|
|
/// <param name="value">要序列化的配置对象。</param>
|
|
/// <returns>带尾随换行的 YAML 文本。</returns>
|
|
public static string Serialize<TValue>(TValue value)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(value);
|
|
|
|
var yaml = Serializer.Serialize(value);
|
|
return yaml.EndsWith('\n')
|
|
? yaml
|
|
: $"{yaml}{Environment.NewLine}";
|
|
}
|
|
}
|