/// <summary> /// Allows the definition of an inline specification to be applied to each item in a collection. /// </summary> /// <example> /// Check(cust => cust.ContactCollection).Required() /// .ForEachSpecification<Contact>( spec => spec.Check(c => c.LastName).Required(), "Contacts" ); /// </example> /// <typeparam name="TCollectionType">The type of instances contained in the collection.</typeparam> /// <param name="rules"><see cref="Action<Validates<TCollectionType>>"/></param> /// <param name="itemName">Name of property to use in notification message.</param> /// <returns><see cref="IAndOr<T, TProperty>"/></returns> public IAndOr <T, TProperty> ForEachSpecification <TCollectionType>(Action <Validates <TCollectionType> > rules, string itemName) { var specification = new SpecificationExpression <TCollectionType>(); rules(specification); var specRule = new ForEachSpecificationRule <T, TProperty, TCollectionType>(specification, itemName); return(AddRuleAndReturnActionJoin(specRule)); }
/// <summary> /// Sets Specification used to validate this Property to the Default /// </summary> /// <returns><see cref="IAndOr<T, TProperty>"/></returns> public IAndOr <T, TProperty> Specification(Action <Validates <TProperty> > rules) { var specification = new SpecificationExpression <TProperty>(); rules(specification); var specRule = new SpecificationRule <T, TProperty>(specification); return(AddRuleAndReturnActionJoin(specRule)); }
public static void Assert(Action<Validates<object>> rules) { var spec = new SpecificationExpression<object>(rules); var vn = ValidationCatalog.Validate(spec.Instance, spec); //var vn = spec.Validate(spec.Instance); if (!vn.IsValid) { throw new ValidationException("Invalid " + spec.Instance.GetType().ToString(), vn); } }
public static ValidationNotification Validate(Action<Validates<object>> rules) { var spec = new SpecificationExpression<object>(rules); return spec.Validate(spec.Instance); }