【发布时间】:2014-07-22 23:43:04
【问题描述】:
否则我总是需要在执行任何其他验证之前检查该值是否为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
});
【问题讨论】:
标签: c# asp.net asp.net-mvc fluentvalidation fluentvalidation-2.0