Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Created February 10, 2011 18:46
Show Gist options
  • Save davidalpert/821081 to your computer and use it in GitHub Desktop.
Save davidalpert/821081 to your computer and use it in GitHub Desktop.
Chained RuleFor (useful when several RuleFor's share a common predicate)
When(x => x.Id != 0)
.Check(RuleFor(x => x.Age).GreaterThan(4))
.Check(RuleFor(x => x.Discount).Equal(10m))
.Unless(x => x.Id == 5);
Check(RuleFor(x => x.Age).GreaterThan(4))
.Check(RuleFor(x => x.Discount).Equal(10m))
.Unless(x => x.Id == 5);
RuleFor(x => x.Age).GreaterThan(4).When(x => x.Id != 0).Unless(x => x.Id == 5);
RuleFor(x => x.Discount).Equal(10m).When(x => x.Id != 0).Unless(x => x.Id == 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment