I have a collection validator class which, overrides the validate function to load data. I'm trying to add a when on a rule for each that applies to the item passed in and not the collection
public class ACAStatusAdjustmentCollectionValidator
: BaseValidator<ItemCollection<IEmployeeACAStatus>>
{
public ACAStatusAdjustmentCollectionValidator(ISecureReadContext isolatedContext) : base(isolatedContext)
{
this.RuleForEach(x => x.Items).Must(this.SomeValidation)
//This when is based off of the collection items instead of the item itself
//.When(x => x.);
}
}
In my scenario I cannot use a collection validator. How can I specify a when On in the rule foreach, without checking my when Inside of the function
Had the same question today and found the answer. One can use the .Where() filter for that:
this.RuleForEach(x => x.Items).Where(item => <condition>).Must(this.SomeValidation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With