IValidator - Parametric/Simple.Validation GitHub Wiki
Create a class that implements IValidator<T>
The AppliesTo method will receive a rulesSet. If your validator is conditionally executed based on rulesSet, you should check the rulesSet. Return true to apply the validation, otherwise return false.
Validate() will be passed the object to validate. You can do any kind of tests you wish against the object under validation. Some simple validation utilities have been provided for common property-level validation.
Please see the [guidelines](IValidator Guidelines) on IValidator implementations.
// Property level Validation public class SubmitLoanApplicationValidator : IValidator { const int MinLoanAmount = 50000; const int MaxLoanAmount = 1500000; const int MinCreditScore = 500; const int MaxCreditScore = 830; public bool AppliesTo(string rulesSet) { return rulesSet == "Submit"; } public IEnumerable Validate(LoanApplication value) { var loanAmountResults = Properties<LoanApplication> .For(e => e.LoanAmount) .GreaterThanOrEqualTo(MinLoanAmount) .LessThanOrEqualTo(MaxLoanAmount) .Message("Loan amount must be between {0:C} and {1:C}", MinLoanAmount, MaxLoanAmount) .Validate(value) ; var creditScoreResults = Properties<LoanApplication> .For(e => e.CreditScore) .GreaterThanOrEqualTo(MinCreditScore) .LessThanOrEqualTo(MaxCreditScore) .Message("Credit score must be between {0} and {1}", MinCreditScore, MaxCreditScore) .Validate(value) ; var results = loanAmountResults.Concat(creditScoreResults); return results; } }