Skip to content

EnumerablePropertyValidator

crmckenzie edited this page Apr 26, 2012 · 2 revisions

Used to validate Collection properties. This validator is most easily used through the Fluent Properties API

Sample

            yield return Properties<Employee>
                .For(e => e.ContactInfo)
                .Required()
                .Count(1)
                .Unique(c => c.Type)
                .Cascade("Save");

Supported Methods:

  • Cascade() - Will execute Validator.Validate and aggregate the results for each element of the collection where T is the type of the element.
  • Cascade<T> - will execute Validator.Validate and aggregate the results for each element of the collection where T is a supertype of the element.
  • Count() - requires that the Count of items in the collection be in the specified range.
  • If() - specifies a condition under which the validator will be executed.
  • Message() - Specifies the message to be returned if the validation fails.
  • NotRequired() - The property is not required. If the property does not have a value, no other checks will be run.
  • Required() - The property is required.
  • Severity() - Specifies the severity of the ValidationResult if the validator fails.
  • Type() - Specifies the type of the ValidationResult if the validator fails.
  • Unique() - Verifies that the elements of the collection are unique. By default, this is a reference check. Overloads of the Unique() function can accept an EqualityComparer, a predicate, or a selector.
  • UsingComparer() - Specifies an instance of IEqualityComparer<T> to use to validate uniqueness.