Пример #1
0
        /// <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&lt;Contact, ContactSpecification&gt;("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&lt;T, TProperty&gt;"/></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));
        }
Пример #2
0
        /// <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&ltContact&gt( spec => spec.Check(c =&gt c.LastName).Required(), "Contacts" );
        /// </example>
        /// <typeparam name="TCollectionType">The type of instances contained in the collection.</typeparam>
        /// <param name="rules"><see cref="Action&lt;Validates&lt;TCollectionType&gt;&gt;"/></param>
        /// <param name="itemName">Name of property to use in notification message.</param>
        /// <returns><see cref="IAndOr&lt;T, TProperty&gt;"/></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));
        }
Пример #3
0
        /// <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&lt;Contact&gt;();
        /// </example>
        /// <typeparam name="TCollectionType">The type of instances contained in the collection.</typeparam>
        /// <returns><see cref="IAndOr&lt;T, TProperty&gt;"/></returns>
        public IAndOr <T, TProperty> ForEachSpecification <TCollectionType>()
        {
            var specRule = new ForEachSpecificationRule <T, TProperty, TCollectionType>();

            return(AddRuleAndReturnActionJoin(specRule));
        }