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`?
```
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`?