【发布时间】:2016-09-16 06:52:32
【问题描述】:
客户端验证适用于“公司名称”,但对于继承的类,即运输和计费它不起作用。请提出解决方案。
[Validator(typeof(ClientValidator))]
public class Client
{
public string CompanyName{get;set;}
private volatile Contact Shipping = null;
private volatile Contact Billing = null;
}
public class Contact : Address
{
}
public class Address
{
public String Name{get;set;}
public String Phone{get;set;}
}
public class ClientValidator : AbstractValidator<Client>
{
public ClientValidator()
{
RuleFor(x => x.CompanyName).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Shipping.Name).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Shipping.Phone).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Billing.Name).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Billing.Phone).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
}
}
【问题讨论】:
标签: c# fluentvalidation