Skip to content

2.2. Must and MustNot validations

hugoj0s3 edited this page Apr 23, 2018 · 2 revisions

Must example:

const string failMessage = "were you born tomorrow ?";
static Func<DateTime, bool> rule = x => (x <= DateTime.Today);

ICompositeValidation<Person> validations = new CompositeValidation<Person>()
 .Must(nameof(Person.BirthDate), p => p.BirthDate, rule, failMessage);

Adding a MustValidation object.

Must not example:

const string failMessage = "were you born tomorrow ?";
static Func<DateTime, bool> rule = x => (x > DateTime.Today);

ICompositeValidation<Person> validations = new CompositeValidation<Person>()
 .MustNot(nameof(Person.BirthDate), p => p.BirthDate, rule, failMessage);

Adding a MustNotValidation object.