Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Closed Unassigned: CascadeMode.StopOnFirstFailure seems to be ignored [7197]

$
0
0
I have a model to validate:
```
public class BarcodeSearchCriteria
{
public string Barcode { get; set; }
public BarcodeType BarcodeType { get; set; } // enum
}
```

and a validator doing it:
```
public class BarcodeSearchCriteriaValidator : AbstractValidator<BarcodeSearchCriteria>
{
public BarcodeSearchCriteriaValidator()
{
CascadeMode = CascadeMode.StopOnFirstFailure;

RuleFor(x => x.Barcode).NotNull();
RuleFor(x => x.BarcodeType).NotEmpty();
RuleFor(x => x).
.Must(c =>
{
switch (c.BarcodeType)
{
case BarcodeType.EAN:
return c.Barcode.Length == 13;
case BarcodeType.UPC:
return c.Barcode.Length == 12;
default:
return false;
}
});
.WithName("BarcodeLength");
}
```

Why in case when `Barcode` is null it doesn't stop after the first rule failed but throws `NullReferenceException`?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>