我有一个班级:
public class CustomerType
{
public int Number { get; set; }
}
验证错误的枚举:
public enum CustomerTypeError
{
None,
NotNumber,
}
然后我有一个验证器类,目前看起来像这样:
public class CustomerTypeValidator : AbstractValidator<CustomerType>
{
public CustomerTypeValidator()
{
RuleFor(x => x.Number).GreaterThanOrEqualTo("").WithMessage("Number must be greater than 0.");
}
}
我不想对邮件进行硬编码,而且我没有使用资源文件,因为这是应用程序的服务器端。我想返回一个CustomerTypeError值。
这可能吗?
答案 0 :(得分:0)
我使用.WithState()然后从ValidationFailure对象读取CUstomState。这样就可以了。