-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Khomutov edited this page Dec 18, 2012
·
7 revisions
Create an extension method along the lines of:
public ValidationResults ValidateCollectionWith<T>(this IEnumerable<T> collection).CountGreaterThan( number).CountLessThanOrEqualTo(number).Unique();
this is more believable
public static CollectionValidator<T> BuildValidator<T>(this IEnumerable<T> collection);
and to get validation results use Validate() method:
List<T> collection;
ValidationResults results = collection.BuildValidator().CountGreaterThan(number).CountLessThanOrEqualTo( number).Unique().Validate();
this illustrates example of using validation of each object in collection:
List<T> collection;
var result = collection.BuildValidator().ElementValidation(x => x.NotNull().MaxLength(10).RegEx("^[0-9]")).Validate();