public void When(Func <T, bool> predicate, Action action) { var propertyRules = new List <IValidationRule>(); Action <IValidationRule> onRuleAdded = propertyRules.Add; using (NestedValidators.OnItemAdded(onRuleAdded)) { action(); } propertyRules.ForEach(x => x.ApplyCondition(ctx => predicate((T)ctx.InstanceToValidate))); }
public void RuleSet(string ruleSetName, Action action) { if (string.IsNullOrEmpty(ruleSetName)) { throw new ArgumentNullException("A name must be specified when calling RuleSet."); } if (action == null) { throw new ArgumentNullException("A ruleset definition must be specified when calling RuleSet."); } using (NestedValidators.OnItemAdded(r => r.RuleSet = ruleSetName)) { action(); } }