Пример #1
0
        }          // func InvokeExpression

        private static Expression InvokeMemberExpression(Scope scope, Token tStart, Expression instance, string sMember, InvokeResult result, ArgumentsList arguments)
        {
            if (LuaEmit.IsDynamicType(instance.Type))
            {
                return(EnsureInvokeResult(scope, tStart,
                                          DynamicExpression.Dynamic(scope.Runtime.GetInvokeMemberBinder(sMember, arguments.CallInfo), typeof(object),
                                                                    new Expression[] { ConvertExpression(scope.Runtime, tStart, instance, typeof(object)) }.Concat(
                                                                        from c in arguments.Expressions select Lua.EnsureType(c, typeof(object))
                                                                        ).ToArray()
                                                                    ),
                                          result, instance, sMember
                                          ));
            }
            else
            {
                // look up the method
                MethodInfo method = LuaEmit.FindMethod(
                    LuaType.GetType(instance.Type).GetInstanceMethods(sMember, false),
                    arguments.CallInfo,
                    arguments.Expressions,
                    getExpressionTypeFunction,
                    true);

                if (method != null)
                {
                    return(EnsureInvokeResult(scope, tStart, SafeExpression(() => InvokeMemberExpressionBind(method, scope.Runtime, instance, arguments), tStart), result, instance, sMember));
                }
                else
                {
                    return(InvokeMemberExpressionDynamic(scope, tStart, instance, sMember, result, arguments));
                }
            }
        }         // func InvokeMemberExpression
Пример #2
0
            } // func FallbackInvoke

            public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
            {
                // defer target and all arguments
                if (!target.HasValue || args.Any(c => !c.HasValue))
                {
                    return(Defer(target, args));
                }

                if (target.Value == null)
                {
                    return(errorSuggestion ??
                           new DynamicMetaObject(
                               ThrowExpression(Properties.Resources.rsNilNotCallable, typeof(object)),
                               target.Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(target.Expression, null))
                               ));
                }
                else
                {
                    MethodInfo method =
                        LuaEmit.FindMethod(
                            LuaType.GetType(target.LimitType).GetInstanceMethods(BindingFlags.Public, Name),
                            args,
                            mo => mo.LimitType,
                            true);

                    if (method == null)
                    {
                        if (errorSuggestion != null)
                        {
                            return(errorSuggestion);
                        }
                        return(new DynamicMetaObject(ThrowExpression(String.Format(Properties.Resources.rsMemberNotResolved, target.LimitType.Name, Name), typeof(object)), GetMethodSignatureRestriction(target, args)));
                    }

                    try
                    {
                        Expression expr;
                        if (method.IsStatic)
                        {
                            expr = LuaEmit.BindParameter(lua,
                                                         a => Expression.Call(null, method, a),
                                                         method.GetParameters(),
                                                         (new DynamicMetaObject[] { target }).Concat(args).ToArray(),
                                                         mo => mo.Expression, mo => mo.LimitType, false);
                        }
                        else
                        {
                            expr = LuaEmit.BindParameter(lua,
                                                         a => Expression.Call(EnsureType(target.Expression, target.LimitType), method, a),
                                                         method.GetParameters(),
                                                         args,
                                                         mo => mo.Expression, mo => mo.LimitType, false);
                        }

                        return
                            (new DynamicMetaObject(
                                 EnsureType(expr, typeof(object), true),
                                 GetMethodSignatureRestriction(target, args)
                                 ));
                    }
                    catch (LuaEmitException e)
                    {
                        if (errorSuggestion != null)
                        {
                            return(errorSuggestion);
                        }
                        return(new DynamicMetaObject(ThrowExpression(e.Message, typeof(object)), GetMethodSignatureRestriction(target, args)));
                    }
                }
            } // func FallbackInvokeMember