c#伪代码
如果我有课
**user** **Sports** **Finance** **Health**
John 2 3 0
Dave 0 0 1
Kirby 1 0 4
我可以让PersonValidator验证Person
但是由于Address是一个复杂的类型,有时我想单独验证它,所以我有一个PersonValidator和一个AddressValidator。问题是,如何在PersonValidator中使用AddressValidator?
class Person
{
string Name
date DOB
Address address
}
答案 0 :(得分:5)
您可以调用.SetValidator(IValidator)
方法。
class PersonValidator : AbstractValidator<Person>
{
PersonValidator()
{
// CascadeMode = CascadeMode.StopOnFirstFailure;
RuleFor(c => c.Name)
.NotEmpty().WithErrorCode("name_required");
// Checks that the IEnumerable<Address> has at least 1 item
RuleFor(c => c.Address)
.NotEmpty().WithErrorCode("addresses_required");
RuleForEach(c => c.Address)
.SetValidator(new AddressValidator());
}
}
class AddressValidator : AbstractValidator<Address>
{
AddressValidator()
{
// CascadeMode = CascadeMode.Continue;
RuleFor(c => c.Postcode)
.NotEmpty().WithErrorCode("postcode_required");
}
}
答案 1 :(得分:2)
您可以覆盖验证方法:
plt.axvline(pd.Timedelta(seconds=120).total_seconds, color='r', linestyle='dashed', linewidth=2)
对于异步方法的变化也要这样做。