/// <summary>
        /// Gets a new specification function which corresponds to the logical
        /// combination of the specified objects: <c>AND</c>.
        /// </summary>
        /// <returns>A specification function.</returns>
        /// <param name="spec">A specification function.</param>
        /// <param name="composeWith">A specification expression.</param>
        /// <typeparam name="T">The generic type of the specifications.</typeparam>
        public static ISpecificationFunction <T> And <T>(this ISpecificationFunction <T> spec, ISpecificationExpression <T> composeWith)
        {
            var func1 = GetFunction(spec);
            var func2 = composeWith.GetFunction();

            return(Spec.Func <T>(o => func1(o) && func2(o)));
        }
        /// <summary>
        /// Gets a new specification function which corresponds to the logical
        /// alternation of the specified objects: <c>OR</c>.
        /// </summary>
        /// <returns>A specification function.</returns>
        /// <param name="spec">A specification function.</param>
        /// <param name="composeWith">Another specification function.</param>
        /// <typeparam name="T">The generic type of the specifications.</typeparam>
        public static ISpecificationFunction <T> Or <T>(this ISpecificationFunction <T> spec, ISpecificationFunction <T> composeWith)
        {
            var func1 = GetFunction(spec);
            var func2 = GetFunction(composeWith);

            return(Spec.Func <T>(o => func1(o) || func2(o)));
        }
示例#3
0
        /// <summary>
        /// Transforms the specification to a target type, using a selector function.
        /// </summary>
        /// <returns>The transformed specification function.</returns>
        /// <param name="selector">A selector to specify how an instance of the transformed/target type may be used to get an instance of the originally-specified type.</param>
        /// <typeparam name="TTarget">The target type.</typeparam>
        public ISpecificationFunction <TTarget> To <TTarget>(Func <TTarget, TOrigin> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            var func = spec.GetFunction();
            Func <TTarget, bool> transformed = target => func(selector(target));

            return(Spec.Func(transformed));
        }
        /// <summary>
        /// Gets a new specification function which corresponds to the logical
        /// negation of the specified object: <c>NOT</c>.
        /// </summary>
        /// <returns>A specification function.</returns>
        /// <param name="spec">A specification function.</param>
        /// <typeparam name="T">The generic type of the specification.</typeparam>
        public static ISpecificationFunction <T> Not <T>(this ISpecificationFunction <T> spec)
        {
            var func = GetFunction(spec);

            return(Spec.Func <T>(o => !func(o)));
        }
示例#5
0
 /// <summary>
 /// Gets a specification function which copies the specified specification expression.
 /// </summary>
 /// <returns>A specification function.</returns>
 /// <param name="spec">A specification expression.</param>
 /// <typeparam name="T">The generic type of the specification.</typeparam>
 public static ISpecificationFunction <T> AsSpecificationFunction <T>(this ISpecificationExpression <T> spec)
 {
     return(Spec.Func(spec.GetFunction()));
 }