namespace GFramework.Game.Config; /// /// 描述一个 YAML 配置表注册项的参数集合。 /// 该选项对象用于替代不断增加的位置参数重载, /// 让消费者在启用 schema 校验、主键比较器或未来扩展项时仍能保持调用点可读。 /// /// 配置主键类型。 /// 配置值类型。 public sealed class YamlConfigTableRegistrationOptions where TKey : notnull { private const string TableNameCannotBeNullOrWhiteSpaceMessage = "Table name cannot be null or whitespace."; private const string RelativePathCannotBeNullOrWhiteSpaceMessage = "Relative path cannot be null or whitespace."; /// /// 使用最小必需参数创建配置表注册选项。 /// /// 运行时配置表名称。 /// 相对配置根目录的子目录。 /// 配置项主键提取器。 /// /// 当 为 null、空字符串或空白字符串时抛出。 /// /// 为 null 时抛出。 public YamlConfigTableRegistrationOptions( string tableName, string relativePath, Func keySelector) { if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentException(TableNameCannotBeNullOrWhiteSpaceMessage, nameof(tableName)); } if (string.IsNullOrWhiteSpace(relativePath)) { throw new ArgumentException(RelativePathCannotBeNullOrWhiteSpaceMessage, nameof(relativePath)); } ArgumentNullException.ThrowIfNull(keySelector); TableName = tableName; RelativePath = relativePath; KeySelector = keySelector; } /// /// 获取运行时配置表名称。 /// public string TableName { get; } /// /// 获取相对配置根目录的子目录。 /// public string RelativePath { get; } /// /// 获取相对配置根目录的 schema 文件路径。 /// 当该值为空时,当前注册项不会启用 schema 校验。 /// public string? SchemaRelativePath { get; init; } /// /// 获取配置项主键提取器。 /// public Func KeySelector { get; } /// /// 获取可选的主键比较器。 /// public IEqualityComparer? Comparer { get; init; } }