/// <summary> /// Allows the enforcement of a specific specification to be applied to each item in a collection. /// </summary> /// <example> /// Check(cust => cust.ContactCollection).Required() /// .ForEachSpecification<Contact, ContactSpecification>("Contacts"); /// </example> /// <param name="itemName">Tne name the property to use when a notification is generated.</param> /// <typeparam name="TCollectionType">The type of instances contained in the collection.</typeparam> /// <typeparam name="TCollectionSpecType">The Specification type to apply to each item in the collection.</typeparam> /// <returns><see cref="IAndOr<T, TProperty>"/></returns> public IAndOr <T, TProperty> ForEachSpecification <TCollectionType, TCollectionSpecType>(string itemName) where TCollectionSpecType : Validates <TCollectionType>, new() { var specRule = new ForEachSpecificationRule <T, TProperty, TCollectionType, TCollectionSpecType>(itemName); return(AddRuleAndReturnActionJoin(specRule)); }
/// <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> /// Allows the enforcement of the default specification to be applied to each item in a collection. /// </summary> /// <example> /// Check(cust => cust.Contacts).Required() /// .ForEachSpecification<Contact>(); /// </example> /// <typeparam name="TCollectionType">The type of instances contained in the collection.</typeparam> /// <returns><see cref="IAndOr<T, TProperty>"/></returns> public IAndOr <T, TProperty> ForEachSpecification <TCollectionType>() { var specRule = new ForEachSpecificationRule <T, TProperty, TCollectionType>(); return(AddRuleAndReturnActionJoin(specRule)); }