增加参数验证

This commit is contained in:
ww-rm
2025-10-26 16:22:49 +08:00
parent 9d9edb8bc4
commit 81d9224658

View File

@@ -255,14 +255,19 @@ namespace SpineViewerCLI
}; };
OptScale.Validators.Add(r => OptScale.Validators.Add(r =>
{ {
if (r.Tokens.Count > 0 && float.TryParse(r.Tokens[0].Value, out var val) && val < 0) if (r.Tokens.Count > 0 && float.TryParse(r.Tokens[0].Value, out var v) && v < 0)
r.AddError($"{OptScale.Name} must be non-negative."); r.AddError($"{OptScale.Name} must be non-negative.");
}); });
OptTime.Validators.Add(r => OptTime.Validators.Add(r =>
{ {
if (r.Tokens.Count > 0 && float.TryParse(r.Tokens[0].Value, out var val) && val < 0) if (r.Tokens.Count > 0 && float.TryParse(r.Tokens[0].Value, out var v) && v < 0)
r.AddError($"{OptTime.Name} must be non-negative."); r.AddError($"{OptTime.Name} must be non-negative.");
}); });
OptSpeed.Validators.Add(r =>
{
if (r.Tokens.Count > 0 && float.TryParse(r.Tokens[0].Value, out var v) && v < 0)
r.AddError($"{OptSpeed.Name} must be non-negative.");
});
// 用反射查找自己所有的公开属性是 Argument 或者 Option 的 // 用反射查找自己所有的公开属性是 Argument 或者 Option 的
foreach (var prop in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) foreach (var prop in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))