I have a property that has multiple rules that need to be applied. But each rule has a condition for when to apply the rule to the property.
I've defined it as
I've defined it as
RuleFor(x=>x.Value).BetweenInclusive(0,14).When(x=>x.Code == 12)
.WithMessage("pH out of range.")
.BetweenInclusive(6.9,9).When(x=>x.Code == 12).WithState(x=> ValidationStates.Warning)
.WithMessage("pH is outside of normal range.")
.Must(BeDefinedToThousands).When(x=>codes.Contains(x.Code))
.WithMessage("Must be reported to nearest thousandths");
But is this the right way to do it? Or Should I instead use top level When and define each rule separately?