Beispiel #1
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            this.arguments = node.Arguments
                             .Select(x => ValueExtractor.FindValueWithin(x))
                             .ToArray();

            return(Expression.Constant(this.arguments));
        }
        public override Expression Visit(Expression node)
        {
            if (node.NodeType == ExpressionType.Convert || node.NodeType == ExpressionType.Call)
            {
                return(base.Visit(node));
            }

            object value;

            if (ValueExtractor.TryFindValueWithin(node, out value))
            {
                this.argumentFilter = new IsArgumentFilter(value);
                return(node);
            }

            return(node);
        }
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var filterMethod = node
                               .Method
                               .DeclaringType
                               .GetTypeInfo()
                               .DeclaredMethods
                               .Where(
                declaredMethod =>
                declaredMethod.IsStatic &&
                declaredMethod.Name == node.Method.Name + "Filter" &&
                declaredMethod.GetParameters().Length == node.Arguments.Count)
                               .FirstOrDefault();

            if (filterMethod != null && filterMethod.ReturnType == typeof(IArgumentFilter))
            {
                if (node.Method.IsGenericMethod)
                {
                    filterMethod = filterMethod.MakeGenericMethod(node.Method.GetGenericArguments());
                }

                var argumentsToFilterMethod = new object[node.Arguments.Count];

                for (var i = 0; i < argumentsToFilterMethod.Length; ++i)
                {
                    argumentsToFilterMethod[i] = ValueExtractor.FindValueWithin(node.Arguments[i]);
                }

                this.argumentFilter = filterMethod.Invoke(null, argumentsToFilterMethod) as IArgumentFilter;
            }
            else
            {
                object value;

                if (ValueExtractor.TryFindValueWithin(node, out value))
                {
                    this.argumentFilter = new IsArgumentFilter(value);
                }
            }

            return(node);
        }