否则,我总是需要null
在执行任何其他验证之前检查该值是否存在。如果我有许多正在使用的自定义检查,这有点烦人Must()
。
我放在NotEmpty()
它的最顶部,因此它已经返回false,是否可以停在那里?
例子
RuleFor(x => x.Name)
.NotEmpty() // Can we not even continue if this fails?
.Length(2, 32)
.Must(x =>
{
var reserved = new[] {"id", "email", "passwordhash", "passwordsalt", "description"};
return !reserved.Contains(x.ToLowerInvariant()); // Exception, x is null
});