示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpressionCallMatcher"/> class.
        /// </summary>
        /// <param name="callSpecification">The call specification.</param>
        /// <param name="validatorFactory">The validator factory.</param>
        public ExpressionCallMatcher(LambdaExpression callSpecification, ArgumentValidatorFactory validatorFactory, MethodInfoManager methodInfoManager)
        {
            this.methodInfoManager = methodInfoManager;
            this.Method            = GetMethodInfo(callSpecification);

            this.argumentValidators = GetArgumentValidators(callSpecification, validatorFactory).ToArray();
            this.argumentsPredicate = this.ArgumentsMatchesArgumentValidators;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpressionCallMatcher"/> class.
        /// </summary>
        /// <param name="callSpecification">The call specification.</param>
        /// <param name="validatorFactory">The validator factory.</param>
        public ExpressionCallMatcher(LambdaExpression callSpecification, ArgumentValidatorFactory validatorFactory)
        {
            Guard.IsNotNull(callSpecification, "callSpecification");
            Guard.IsNotNull(validatorFactory, "validatorFactory");

            this.method = GetMethodInfo(callSpecification);

            this.argumentValidators = GetArgumentValidators(callSpecification, validatorFactory).ToArray();
        }
示例#3
0
        private static IEnumerable <IArgumentValidator> GetArgumentValidators(LambdaExpression callSpecification, ArgumentValidatorFactory validatorFactory)
        {
            var methodExpression = callSpecification.Body as MethodCallExpression;

            if (methodExpression != null)
            {
                return
                    (from argument in methodExpression.Arguments
                     select validatorFactory.GetArgumentValidator(argument));
            }

            return(Enumerable.Empty <IArgumentValidator>());
        }