mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 08:44:29 +08:00
- 修复 Mediator 集成测试中的阻塞等待、缓存竞态与共享状态原子性问题 - 补充 YamlConfig 运行时模型的构造期约束与 exception XML 文档 - 新增 模型契约回归测试并更新 analyzer warning reduction 恢复文档
67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
namespace GFramework.Game.Config;
|
|
|
|
/// <summary>
|
|
/// 表示一个数组节点上声明的元素数量、去重与 contains 匹配计数约束。
|
|
/// 该模型与标量约束拆分保存,避免数组节点继续共享不适用的标量字段。
|
|
/// </summary>
|
|
internal sealed class YamlConfigArrayConstraints
|
|
{
|
|
/// <summary>
|
|
/// 初始化数组约束模型。
|
|
/// </summary>
|
|
/// <param name="minItems">最小元素数量约束。</param>
|
|
/// <param name="maxItems">最大元素数量约束。</param>
|
|
/// <param name="uniqueItems">是否要求数组元素唯一。</param>
|
|
/// <param name="containsConstraints">数组 contains 约束;未声明时为空。</param>
|
|
/// <exception cref="ArgumentOutOfRangeException">当 <paramref name="minItems"/> 或 <paramref name="maxItems"/> 为负数时抛出。</exception>
|
|
/// <exception cref="ArgumentException">当 <paramref name="minItems"/> 大于 <paramref name="maxItems"/> 时抛出。</exception>
|
|
public YamlConfigArrayConstraints(
|
|
int? minItems,
|
|
int? maxItems,
|
|
bool uniqueItems,
|
|
YamlConfigArrayContainsConstraints? containsConstraints)
|
|
{
|
|
if (minItems is < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(minItems), minItems, "minItems 不能为负数。");
|
|
}
|
|
|
|
if (maxItems is < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(maxItems), maxItems, "maxItems 不能为负数。");
|
|
}
|
|
|
|
if (minItems.HasValue &&
|
|
maxItems.HasValue &&
|
|
minItems.Value > maxItems.Value)
|
|
{
|
|
throw new ArgumentException("minItems 不能大于 maxItems。", nameof(minItems));
|
|
}
|
|
|
|
MinItems = minItems;
|
|
MaxItems = maxItems;
|
|
UniqueItems = uniqueItems;
|
|
ContainsConstraints = containsConstraints;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取最小元素数量约束。
|
|
/// </summary>
|
|
public int? MinItems { get; }
|
|
|
|
/// <summary>
|
|
/// 获取最大元素数量约束。
|
|
/// </summary>
|
|
public int? MaxItems { get; }
|
|
|
|
/// <summary>
|
|
/// 获取是否要求数组元素唯一。
|
|
/// </summary>
|
|
public bool UniqueItems { get; }
|
|
|
|
/// <summary>
|
|
/// 获取数组 contains 约束;未声明时返回空。
|
|
/// </summary>
|
|
public YamlConfigArrayContainsConstraints? ContainsConstraints { get; }
|
|
}
|