static SymbolExtensions()
        {
            //Ensure not already ran.
            if (false.Equals(TypedConstantExpressionType == null)
                | false.Equals(InstanceMethodCallExpressionNType == null)
                | false.Equals(TypedConstantExpressionValueProperty == null))
            {
                return;
            }

            //For example
            //Expression<Action> ConstantExpression = () => Binary.Nihil.Equals(null);

            //Rather than take a reference to the assembly achieve the same thing by using reflection a single time on what should be equal to a TypedConstantExpression.

            Expression <Action> TypedConstantExpression = () => typeof(Nullable <>).GetType();

            MethodCallExpression methodCallExpression = TypedConstantExpression.Body as MethodCallExpression;

            //InstanceMethodCallExpressionN
            InstanceMethodCallExpressionNType = methodCallExpression.GetType();

            //The body as a MethodCall reveals the Object which is really a TypedConstantExpression
            methodCallExpression = TypedConstantExpression.Body as MethodCallExpression;

            //Store the Type of that object.
            TypedConstantExpressionType = methodCallExpression.Object.GetType();

            //Store the type
            TypedConstantExpressionValueProperty = IntrospectionExtensions.GetTypeInfo(TypedConstantExpressionType).GetProperty("Value");

            TypedConstantExpression = null;

            methodCallExpression = null;
        }
Exemple #2
0
 //
 // Summary:
 //     Visits the children of the System.Linq.Expressions.MethodCallExpression.
 //
 // Parameters:
 //   node:
 //     The expression to visit.
 //
 // Returns:
 //     The modified expression, if it or any subexpression was modified; otherwise,
 //     returns the original expression.
 protected override Expression VisitMethodCall(MethodCallExpression node)
 {
     Console.WriteLine("VisitMethodCall:");
     Console.WriteLine(node.Method.ToString());
     Console.WriteLine('\t' + node.GetType().ToString());
     Console.WriteLine('\t' + node.ToString());
     Console.WriteLine(node);
     return(base.VisitMethodCall(node));
 }
Exemple #3
0
        public static void CheckCallFactoryInstanceN()
        {
            const int N = 4;

            ParameterExpression obj = Expression.Parameter(typeof(MS));

            ConstantExpression[] args = Enumerable.Range(0, N).Select(i => Expression.Constant(i)).ToArray();

            MethodCallExpression expr = Expression.Call(obj, typeof(MS).GetMethod("I" + N), args);

            if (!PlatformDetection.IsNetNative) // .Net Native blocks internal framework reflection.
            {
                Assert.Equal("InstanceMethodCallExpressionN", expr.GetType().Name);
            }

            Assert.Same(obj, expr.Object);

            Assert.Equal(N, expr.ArgumentCount);
            for (var i = 0; i < N; i++)
            {
                Assert.Same(args[i], expr.GetArgument(i));
            }

            Collections.ObjectModel.ReadOnlyCollection <Expression> arguments = expr.Arguments;
            Assert.Same(arguments, expr.Arguments);

            Assert.Equal(N, arguments.Count);
            for (var i = 0; i < N; i++)
            {
                Assert.Same(args[i], arguments[i]);
            }

            MethodCallExpression updated = expr.Update(obj, arguments.ToList());

            Assert.Same(expr, updated);

            var visited = (MethodCallExpression) new NopVisitor().Visit(expr);

            Assert.Same(expr, visited);

            var visitedObj = (MethodCallExpression) new VisitorObj().Visit(expr);

            Assert.NotSame(expr, visitedObj);
            Assert.NotSame(obj, visitedObj.Object);
            Assert.Same(arguments, visitedObj.Arguments);

            var visitedArgs = (MethodCallExpression) new VisitorArgs().Visit(expr);

            Assert.NotSame(expr, visitedArgs);
            Assert.Same(obj, visitedArgs.Object);
            Assert.NotSame(arguments, visitedArgs.Arguments);
        }
Exemple #4
0
        private static int PrintMethodCall(MethodCallExpression expression)
        {
            Write("ToString: " + expression);
            Write("GetType: " + expression.GetType());
            Write("NodeType: " + expression.NodeType);
            Write("Type: " + expression.Type);
            foreach (var argument in expression.Arguments)
            {
                Write("Argument: " + argument);
            }
            Write("Method.Name: " + expression.Method.Name);
            Write("Object: " + expression.Object);
            PrintUnkwnown(expression.Object);

            return(0);
        }
        public static void CheckCallFactoryStaticN()
        {
            const int N = 6;

            ConstantExpression[] args = Enumerable.Range(0, N).Select(i => Expression.Constant(i)).ToArray();

            MethodCallExpression expr = Expression.Call(typeof(MS).GetMethod("S" + N), args);

            Assert.Equal("MethodCallExpressionN", expr.GetType().Name);

            Assert.Equal(N, expr.ArgumentCount);
            for (var i = 0; i < N; i++)
            {
                Assert.Same(args[i], expr.GetArgument(i));
            }

            Collections.ObjectModel.ReadOnlyCollection <Expression> arguments = expr.Arguments;
            Assert.Same(arguments, expr.Arguments);

            Assert.Equal(N, arguments.Count);
            for (var i = 0; i < N; i++)
            {
                Assert.Same(args[i], arguments[i]);
            }

            MethodCallExpression updated = expr.Update(null, arguments);

            Assert.Same(expr, updated);

            var visited = (MethodCallExpression) new NopVisitor().Visit(expr);

            Assert.Same(expr, visited);

            var visitedArgs = (MethodCallExpression) new VisitorArgs().Visit(expr);

            Assert.NotSame(expr, visitedArgs);
            Assert.Same(null, visitedArgs.Object);
            Assert.NotSame(arguments, visitedArgs.Arguments);
        }