Project Description
A small validation framework for .NET that uses a fluent interface and lambda expressions for building validation rules for your business objects.

Example

using FluentValidation;
 
public class CustomerValidator: AbstractValidator<Customer> {
  public CustomerValidator() {
    RuleFor(customer => customer.Surname).NotEmpty();
    RuleFor(customer => customer.Forename).NotEmpty().WithMessage("Please specify a first name");
    RuleFor(customer => customer.Company).NotNull();
    RuleFor(customer => customer.Discount).NotEqual(0).When(customer => customer.HasDiscount);
    RuleFor(customer => customer.Address).Length(20, 250);
    RuleFor(customer => customer.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode");
  }
 
  private bool BeAValidPostcode(string postcode) {
    // custom postcode validating logic goes here
  }
}
 
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();
ValidationResult results = validator.Validate(customer);
 
bool validationSucceeded = results.IsValid;
IList<ValidationFailure> failures = results.Errors;


Documentation


Build Server
TeamCity
Code Coverage
Last Successful Build
Last edited Dec 23 2008 at 2:57 PM by JeremyS, version 13
Comments
leblanc wrote  Oct 23 2008 at 4:52 PM 
cool. I'll have to check this code out.

you might be interested in: http://www.codeplex.com/NPEG
create composite delegates similar to how you are doing it.

insect wrote  Nov 4 2008 at 9:36 PM 
Great tool! Thank you.

Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | CodePlex Blog | Version 2008.12.9.14291