Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Created Issue: RuleForEach - Feature Request [7118]

$
0
0
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..)

Advantages:
- Allows each item in a collection to be treated as a property of the parent.
- A separate child validation class does not have to be defined
- Brings the capability to validate collections of primitives

Risks:
- Could easily be misused as a way to validate properties on a child class - not the intended use
- Not sure how easily it could be incorporated into the current code base

Usage Examples:

RuleForEach(person => person.NickNames).Length(1,50);

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);


Viewing all articles
Browse latest Browse all 1917


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>