예제 #1
0
        static System.Reflection.MethodInfo VisitPow(BinaryExpression node, Expression left, Expression right, ArgumentConversions conversions)
        {
            var types = new Type[2] {
                left.Type, right.Type
            };

            System.Reflection.MethodInfo method = ReflectionHelpers.MathPow;
            if (left.Type.IsPrimitive || right.Type.IsPrimitive)
            {
                var initial = ReflectionUtils.FromSystemType(ref types);
                if (!method.MatchesArgumentTypes(types, conversions))
                {
                    ExecutionException.ThrowArgumentMisMatch(node);
                }
                conversions.SetInitial(initial);
                return(method);
            }
            if (!method.MatchesArgumentTypes(types, conversions))
            {
                ExecutionException.ThrowArgumentMisMatch(node);
            }
            return(method);
        }
예제 #2
0
        public static InvocationExpression Call(Expression instance, System.Reflection.MethodInfo method, params Expression[] arguments)
        {
            NodeList <Expression> args = new NodeList <Expression>(arguments);
            InvocationExpression  exp  = new InvocationExpression(instance, args)
            {
                Method      = method,
                Conversions = new Runtime.ArgumentConversions(args.Count),
                Type        = method.ReturnType
            };

            if (!method.MatchesArgumentTypes(args.Map(ex => ex.Type), exp.Conversions))
            {
                throw new InvalidOperationException("Arguments miss match");
            }
            return(exp);
        }