1
私のプロジェクトでは、私はFluentValidation of .netを使用しています。私はこの検証は、このようなものである適用されているクラス:私はMobileNos of Input
クラスに{null,"7897897897"}
リストを渡すときFluentvalidationのSetCollectionValidatorの奇妙な動作
[Validation(typeof(InputValidator))]
public class Inputs
{
public IEnumerable<string> MobileNos { get; set; }
}
InputValidator.cs
ファイルには、今、この
public class InputValidator: AbstractValidator<Inputs>
{
public BlockMobileInputsValidator()
{
RuleFor(x => x.MobileNos).Cascade(CascadeMode.StopOnFirstFailure).NotEmpty()
.Must(x => x.Count() <= 100).WithMessage("List should not contain more than 100 mobile numbers.")
.SetCollectionValidator(new MobileValidator());
}
}
そしてMobileValidator.cs
public class MobileValidator:AbstractValidator<string>
{
public Mobilevalidator()
{
RuleFor(x => x).Matches("^[6789]\d{9}$").WithMessage("{PropertyValue} is not in correct mobile-number format");
}
}
のようなものですそれは何のエラーも与えておらず、さらなる使用のためにリストが受け入れられる。 私はこの奇妙な動作を理解することができません。 I also tried this
しかしこれも上記の入力に対しては機能しません。
null
の値を受け入れる理由を教えていただけますか?