MakeCallExpression() 공개 메소드

public MakeCallExpression ( Microsoft.Scripting.Actions.Calls.OverloadResolverFactory resolverFactory, MethodInfo method ) : DynamicMetaObject
resolverFactory Microsoft.Scripting.Actions.Calls.OverloadResolverFactory
method System.Reflection.MethodInfo
리턴 System.Dynamic.DynamicMetaObject
예제 #1
0
        internal override Expression GetBoundValue(ActionBinder binder, Type type, Expression instance)
        {
            if (instance == null)
            {
                return(null);
            }

            if (GetIndexParameters().Length > 0)
            {
                // need to bind to a value or parameters to get the value.
                return(binder.ReturnMemberTracker(type, BindToInstance(instance)));
            }

            MethodInfo getter = ResolveGetter();

            if (getter == null || getter.ContainsGenericParameters)
            {
                // no usable getter
                return(null);
            }

            if (getter.IsPublic && getter.DeclaringType.IsPublic)
            {
                return(binder.MakeCallExpression(getter, instance));;
            }

            // private binding is just a call to the getter method...
            return(MemberTracker.FromMemberInfo(getter).Call(binder, instance));
        }
예제 #2
0
        protected internal override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance)
        {
            if (instance != null && IsStatic)
            {
                return(null);
            }

            if (GetIndexParameters().Length > 0)
            {
                // need to bind to a value or parameters to get the value.
                return(binder.ReturnMemberTracker(type, BindToInstance(instance)));
            }

            MethodInfo getter = ResolveGetter(binder.PrivateBinding);

            if (getter == null || getter.ContainsGenericParameters)
            {
                // no usable getter
                return(null);
            }

            if (getter.IsPublic && getter.DeclaringType.IsVisible)
            {
                return(binder.MakeCallExpression(context, getter, instance));
            }

            // private binding is just a call to the getter method...
            return(DefaultBinder.MakeError(((DefaultBinder)binder).MakeNonPublicMemberGetError(context, this, type, instance)));
        }
예제 #3
0
        public override Microsoft.Scripting.Ast.Expression Call(ActionBinder binder, params Expression[] arguments)
        {
            if (Method.IsPublic && Method.DeclaringType.IsVisible)
            {
                // TODO: Need to use MethodBinder in here to make this right.
                return(binder.MakeCallExpression(Method, arguments));
            }

            //methodInfo.Invoke(obj, object[] params)
            if (Method.IsStatic)
            {
                return(Ast.Convert(
                           Ast.Call(
                               Ast.RuntimeConstant(Method),
                               typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                               Ast.Null(),
                               Ast.NewArrayHelper(typeof(object[]), arguments)),
                           Method.ReturnType));
            }

            if (arguments.Length == 0)
            {
                throw new InvalidOperationException("no instance for call");
            }

            return(Ast.Convert(
                       Ast.Call(
                           Ast.RuntimeConstant(Method),
                           typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                           arguments[0],
                           Ast.NewArrayHelper(typeof(object[]), ArrayUtils.RemoveFirst(arguments))),
                       Method.ReturnType));
        }
예제 #4
0
        internal override System.Linq.Expressions.Expression Call(Expression context, ActionBinder binder, params Expression[] arguments)
        {
            if (Method.IsPublic && Method.DeclaringType.IsVisible)
            {
                // TODO: Need to use MethodBinder in here to make this right.
                return(binder.MakeCallExpression(context, Method, arguments));
            }

            //methodInfo.Invoke(obj, object[] params)
            if (Method.IsStatic)
            {
                return(Ast.Convert(
                           Ast.Call(
                               Ast.Constant(Method),
                               typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                               Ast.Constant(null),
                               AstUtils.NewArrayHelper(typeof(object), arguments)
                               ),
                           Method.ReturnType));
            }

            if (arguments.Length == 0)
            {
                throw Error.NoInstanceForCall();
            }

            return(Ast.Convert(
                       Ast.Call(
                           Ast.Constant(Method),
                           typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                           arguments[0],
                           AstUtils.NewArrayHelper(typeof(object), ArrayUtils.RemoveFirst(arguments))
                           ),
                       Method.ReturnType));
        }
예제 #5
0
        internal override DynamicMetaObject Call(OverloadResolverFactory resolverFactory, ActionBinder binder, params DynamicMetaObject[] arguments)
        {
            if (Method.IsPublic && Method.DeclaringType.IsVisible())
            {
                return(binder.MakeCallExpression(resolverFactory, Method, arguments));
            }

            //methodInfo.Invoke(obj, object[] params)
            if (Method.IsStatic)
            {
                return(new DynamicMetaObject(
                           Expression.Convert(
                               Expression.Call(
                                   AstUtils.Constant(Method),
                                   typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                                   AstUtils.Constant(null),
                                   AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(arguments, x => x.Expression))
                                   ),
                               Method.ReturnType
                               ),
                           BindingRestrictions.Empty
                           )
                       );
            }

            if (arguments.Length == 0)
            {
                throw Error.NoInstanceForCall();
            }

            return(new DynamicMetaObject(
                       Expression.Convert(
                           Expression.Call(
                               AstUtils.Constant(Method),
                               typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                               arguments[0].Expression,
                               AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(ArrayUtils.RemoveFirst(arguments), x => x.Expression))
                               ),
                           Method.ReturnType
                           ),
                       BindingRestrictions.Empty
                       ));
        }
예제 #6
0
        public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type) {
            if (!IsStatic || GetIndexParameters().Length > 0) {
                // need to bind to a value or parameters to get the value.
                return binder.ReturnMemberTracker(type, this);
            }

            MethodInfo getter = ResolveGetter(binder.PrivateBinding);
            if (getter == null || getter.ContainsGenericParameters) {
                // no usable getter
                return null;
            }

            if (getter.IsPublic && getter.DeclaringType.IsPublic) {
                return binder.MakeCallExpression(resolverFactory, getter);
            }

            // private binding is just a call to the getter method...
            return MemberTracker.FromMemberInfo(getter).Call(resolverFactory, binder);
        }
예제 #7
0
        public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType)
        {
            if (!IsStatic || GetIndexParameters().Length > 0)
            {
                // need to bind to a value or parameters to get the value.
                return(binder.ReturnMemberTracker(instanceType, this));
            }

            MethodInfo getter = ResolveGetter(instanceType, binder.PrivateBinding);

            if (getter == null || getter.ContainsGenericParameters)
            {
                // no usable getter
                return(null);
            }

            if (getter.IsPublic && getter.DeclaringType.IsPublic())
            {
                return(binder.MakeCallExpression(resolverFactory, getter));
            }

            // private binding is just a call to the getter method...
            return(MemberTracker.FromMemberInfo(getter).Call(resolverFactory, binder));
        }
예제 #8
0
        public override Expression GetValue(Expression context, ActionBinder binder, Type type)
        {
            if (!IsStatic || GetIndexParameters().Length > 0)
            {
                // need to bind to a value or parameters to get the value.
                return(binder.ReturnMemberTracker(type, this));
            }

            MethodInfo getter = ResolveGetter(binder.PrivateBinding);

            if (getter == null || getter.ContainsGenericParameters)
            {
                // no usable getter
                return(null);
            }

            if (getter.IsPublic && getter.DeclaringType.IsPublic)
            {
                return(binder.MakeCallExpression(context, getter));
            }

            // private binding is just a call to the getter method...
            return(MemberTracker.FromMemberInfo(getter).Call(context, binder));
        }
예제 #9
0
        internal override System.Linq.Expressions.Expression Call(Expression context, ActionBinder binder, params Expression[] arguments) {
            if (Method.IsPublic && Method.DeclaringType.IsVisible) {
                // TODO: Need to use MethodBinder in here to make this right.
                return binder.MakeCallExpression(context, Method, arguments);
            }

            //methodInfo.Invoke(obj, object[] params)
            if (Method.IsStatic) {
                return Ast.Convert(
                    Ast.Call(
                        Ast.Constant(Method),
                        typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                        Ast.Constant(null),
                        AstUtils.NewArrayHelper(typeof(object), arguments)
                    ),
                    Method.ReturnType);
            }

            if (arguments.Length == 0) throw Error.NoInstanceForCall();

            return Ast.Convert(
                Ast.Call(
                    Ast.Constant(Method),
                    typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                    arguments[0],
                    AstUtils.NewArrayHelper(typeof(object), ArrayUtils.RemoveFirst(arguments))
                ),
                Method.ReturnType);
        }
예제 #10
0
        internal override DynamicMetaObject Call(OverloadResolverFactory resolverFactory, ActionBinder binder, params DynamicMetaObject[] arguments) {
            if (Method.IsPublic && Method.DeclaringType.IsVisible) {
                return binder.MakeCallExpression(resolverFactory, Method, arguments);
            }

            //methodInfo.Invoke(obj, object[] params)
            if (Method.IsStatic) {
                return new DynamicMetaObject(
                        Ast.Convert(
                            Ast.Call(
                                AstUtils.Constant(Method),
                                typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                                AstUtils.Constant(null),
                                AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(arguments, x => x.Expression))
                            ),
                            Method.ReturnType
                        ),
                        BindingRestrictions.Empty
                    )
                ;
            }

            if (arguments.Length == 0) throw Error.NoInstanceForCall();

            return new DynamicMetaObject(
                Ast.Convert(
                    Ast.Call(
                        AstUtils.Constant(Method),
                        typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                        arguments[0].Expression,
                        AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(ArrayUtils.RemoveFirst(arguments), x => x.Expression))
                    ),
                    Method.ReturnType
                ),
                BindingRestrictions.Empty
            );
        }
예제 #11
0
        public override Microsoft.Scripting.Ast.Expression Call(ActionBinder binder, params Expression[] arguments) {
            if (Method.IsPublic && Method.DeclaringType.IsVisible) {
                // TODO: Need to use MethodBinder in here to make this right.
                return binder.MakeCallExpression(Method, arguments);
            }

            //methodInfo.Invoke(obj, object[] params)
            if (Method.IsStatic) {
                return Ast.Convert(
                    Ast.Call(
                        Ast.RuntimeConstant(Method),
                        typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                        Ast.Null(),
                        Ast.NewArrayHelper(typeof(object[]), arguments)),
                    Method.ReturnType);
            } 

            if (arguments.Length == 0) throw new InvalidOperationException("no instance for call");

            return Ast.Convert(
                Ast.Call(
                    Ast.RuntimeConstant(Method),
                    typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                    arguments[0],
                    Ast.NewArrayHelper(typeof(object[]), ArrayUtils.RemoveFirst(arguments))),
                Method.ReturnType);                       
        }
예제 #12
0
        protected internal override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance) {
            if (instance != null && IsStatic) {
                return null;
            }

            if (GetIndexParameters().Length > 0) {
                // need to bind to a value or parameters to get the value.
                return binder.ReturnMemberTracker(type, BindToInstance(instance));
            }

            MethodInfo getter = GetGetMethod(true);
            if (getter == null || getter.ContainsGenericParameters) {
                // no usable getter
                return null;
            }

            getter = CompilerHelpers.TryGetCallableMethod(getter);

            if (binder.PrivateBinding || CompilerHelpers.IsVisible(getter)) {
                return binder.MakeCallExpression(context, getter, instance);
            }

            // private binding is just a call to the getter method...
            return DefaultBinder.MakeError(((DefaultBinder)binder).MakeNonPublicMemberGetError(context, this, type, instance));
        }