public static void DoWork(Person person) { ModelValidation<Person>.Validate(person) .NullOrEmpty("{0} is required", c => c.FirstName, c => c.LastName) .Null("{0} is required", c=>c.BirthDate) .IsTrue("Must be 21 or older", c=> c < 21, c=>c.Age) .ThrowIfErrors(); Console.WriteLine("This person is cool"); }
public static void DoWork(Person person) { ModelValidation<Person>.Validate(person) .WhenNullOrEmpty("{0} is required", c => c.FirstName, c => c.LastName) .WhenNull("{0} is required", c => c.BirthDate) .WhenTrue("Must be 21 or older", c => c < 21, c => c.Age) .WhenFalse("Must be 21 or older", c => c >= 21, c => c.Age) .WhenNullOrEmpty<int>("No lottory numbers given", c => c.LottoNumbers) .WhenNullOrEmpty("No comments provided", c => c.Comments) .ThrowWhenOneOrMoreConditionsAreMet(); Console.WriteLine("This person is cool"); }