Add a "RuleForEach" method to AbstractValidator that allows validation to be defined for each item in a strongly typed collection but within the scope of the parent. This would be similar to defining rules on a fixed size collection for each item index (e.g. RuleFor(person => person.Orders[0])..., RuleFor(person => person.Orders[1])...., etc..)<br /><br />Advantages:<br />- Allows each item in a collection to be treated as a property of the parent. <br />- A separate child validation class does not have to be defined<br />- Brings the capability to validate collections of primitives <br /><br />Risks:<br />- Could easily be misused as a way to validate properties on a child class - not the intended use<br />- Not sure how easily it could be incorporated into the current code base<br /><br />Usage Examples:<br /><br />RuleForEach(person => person.NickNames).Length(1,50);<br /><br />RuleForEach(workDay => workDay.WorkItems).Must((workDay, workItem) => workDay.Assignments.Any(a => a.WorkItem == workItem).WithMessage("{0} has not been assigned", workItem => workItem.Description());<br /><br />Potential Bad Usage:<br />RuleForEach(person => person.Orders).Must((person, order) => order.Amount <= person.MaxAmountAuthorized).WithMessage("Order for {0} has an amount greater than {1} authorized limit", order => order.ProductName, person => person.Forename);<br />
↧