Ejemplo n.º 1
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            var overloads = GetMethods(binder.Name);

            if (overloads == null)
            {
                return(binder.FallbackInvokeMember(this, args));
            }

            if (Disposed)
            {
                return(new DynamicMetaObject(ThrowObjectDisposedException(typeof(object)), BindingRestrictions.GetInstanceRestriction(Expression, Value)));
            }

            var applicable = overloads.Where(o => (o.IsStatic == !HasSelf) && o.ArgumentTypes.Count == args.Length).ToArray();

            if (applicable.Length == 0)
            {
                return(binder.FallbackInvokeMember(this, args));
            }

            TryInvokeMember invoke   = info.TryInvokeMember;
            var             value    = Expression.Parameter(typeof(object), "value");
            var             fallback = binder.FallbackInvokeMember(this, args);
            var             call     = Expression.Block(
                new[] { value },
                Expression.Condition(
                    test:       Expression.Call(Expression.Constant(info), invoke.GetMethodInfo(), GetSelf(), Expression.Constant(applicable), Expression.Constant(args), value),
                    ifTrue:     value,
                    ifFalse:    fallback.Expression)
                );

            return(new DynamicMetaObject(call, BindingRestrictions.GetInstanceRestriction(Expression, Value)));
        }
Ejemplo n.º 2
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            Logger.Log(LogLevel.Debug, null, "BindInvokeMember");

            var argValues          = Expression.NewArrayInit(typeof(object), args.Select(x => Expression.Convert(x.Expression, typeof(Object))));
            var argNames           = Expression.Constant(binder.CallInfo.ArgumentNames, typeof(IEnumerable <string>));
            var argNamedEnumerable = Expression.Call(typeof(Arguments).GetMethod("From"), argValues, argNames);

            var binderDefault = binder.FallbackInvokeMember(this, args);

            var missingLambda = Expression.Lambda(Expression.Call(
                                                      GetClayBehavior(),
                                                      IClayBehavior_InvokeMemberMissing,
                                                      Expression.Lambda(binderDefault.Expression),
                                                      GetLimitedSelf(),
                                                      Expression.Constant(binder.Name, typeof(string)),
                                                      argNamedEnumerable));

            var call = Expression.Call(
                GetClayBehavior(),
                IClayBehavior_InvokeMember,
                missingLambda,
                GetLimitedSelf(),
                Expression.Constant(binder.Name, typeof(string)),
                argNamedEnumerable);

            var dynamicSuggestion = new DynamicMetaObject(
                call, BindingRestrictions.GetTypeRestriction(Expression, LimitType).Merge(binderDefault.Restrictions));

            return(binder.FallbackInvokeMember(this, args, dynamicSuggestion));
        }
Ejemplo n.º 3
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                // get the default binding the language would return if we weren't involved
                // This will either access a property on MyDynamicObject or it will report
                // an error in a language appropriate manner.
                DynamicMetaObject errorSuggestion = binder.FallbackInvokeMember(this, args);

                // run through the plugins and replace our current rule.  Running through
                // the list forward means the last plugin has the highest precedence because
                // it may throw away the previous rules if it succeeds.
                for (int i = 0; i < Value._plugins.Length; i++)
                {
                    var pluginDo = DynamicMetaObject.Create(Value._plugins[i],
                                                            Expression.Call(
                                                                typeof(MyDynamicObjectOps).GetMethod("GetPlugin"),
                                                                Expression,
                                                                Expression.Constant(i)
                                                                )
                                                            );

                    errorSuggestion = binder.FallbackInvokeMember(pluginDo, args, errorSuggestion);
                }

                // Do we want DynamicMetaObject to have precedence?  If so then we can do
                // one more bind passing what we've produced so far as the rule.  Or if the
                // plugins have precedence we could just return the value.  We'll do that
                // here based upon the member name.

                if (binder.Name == "Foo")
                {
                    return(binder.FallbackInvokeMember(this, args, errorSuggestion));
                }

                return(errorSuggestion);
            }
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                // VbGetBinder calls this method when you read a dynamic property from VB code
                var binderDefault = binder.FallbackInvokeMember(this, args);

                var expression = Expression.Convert(GetIndexExpression(binder.Name), typeof(object));

                var dynamicSuggestion = new DynamicMetaObject(expression, BindingRestrictions.GetTypeRestriction(Expression, LimitType)
                                                              .Merge(binderDefault.Restrictions));

                return(binder.FallbackInvokeMember(this, args, dynamicSuggestion));
            }
Ejemplo n.º 5
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            // Generate a tree like:
            //
            // {
            //   object result;
            //   TryInvokeMember(payload, out result)
            //      ? result
            //      : TryGetMember(payload, out result)
            //          ? FallbackInvoke(result)
            //          : fallbackResult
            // }
            //
            // Then it calls FallbackInvokeMember with this tree as the
            // "error", giving the language the option of using this
            // tree or doing .NET binding.
            //
            Fallback fallback = e => binder.FallbackInvokeMember(this, args, e);

            var call = BuildCallMethodWithResult(
                "TryInvokeMember",
                binder,
                GetExpressions(args),
                BuildCallMethodWithResult(
                    "TryGetMember",
                    new GetBinderAdapter(binder),
                    NoArgs,
                    fallback(null),
                    (e) => binder.FallbackInvoke(e, args, null)
                    ),
                null
                );

            return(fallback(call));
        }
Ejemplo n.º 6
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     return(DynamicTryGetMember(binder.Name,
                                binder.FallbackInvokeMember(this, args).Expression,
                                (tmp) => binder.FallbackInvoke(new DynamicMetaObject(tmp, BindingRestrictions.Empty), args, null).Expression
                                ));
 }
Ejemplo n.º 7
0
        public override DynamicMetaObject/*!*/ BindInvokeMember(InvokeMemberBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
            DynamicMetaObject errorSuggestion = null;
            if (_baseMetaObject != null) {
                errorSuggestion = _baseMetaObject.BindInvokeMember(action, args);
            }
            
            CodeContext context = BinderState.GetBinderState(action).Context;
            IPythonObject sdo = Value;
            PythonTypeSlot foundSlot;

            if (TryGetGetAttribute(context, sdo.PythonType, out foundSlot)) {
                // we'll always fetch the value, go ahead and invoke afterwards.
                return BindingHelpers.GenericCall(action, this, args);
            }

            bool isOldStyle;
            bool systemTypeResolution;
            foundSlot = FindSlot(context, action.Name, sdo, out isOldStyle, out systemTypeResolution);
            if (foundSlot != null && !systemTypeResolution) {
                // we found the member in the type dictionary, not a .NET type, go ahead and
                // do the get & invoke.
                return BindingHelpers.GenericCall(action, this, args);
            }

            // it's a normal .NET member, let the calling language handle it how it usually does
            return action.FallbackInvokeMember(this, args, errorSuggestion);
        }
Ejemplo n.º 8
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                if (IsOverridden("TryInvokeMember"))
                {
                    return(CallMethodWithResult("TryInvokeMember", binder, GetArgArray(args), (e) => binder.FallbackInvokeMember(this, args, e)));
                }
                else if (IsOverridden("TryGetMember"))
                {
                    // Generate a tree like:
                    //
                    // {
                    //   object result;
                    //   TryGetMember(payload, out result) ? FallbackInvoke(result) : fallbackResult
                    // }
                    //
                    // Then it calls FallbackInvokeMember with this tree as the
                    // "error", giving the language the option of using this
                    // tree or doing .NET binding.
                    //
                    return(CallMethodWithResult(
                               "TryGetMember", new GetBinderAdapter(binder), NoArgs,
                               (e) => binder.FallbackInvokeMember(this, args, e),
                               (e) => binder.FallbackInvoke(e, args, null)
                               ));
                }

                return(base.BindInvokeMember(binder, args));
            }
Ejemplo n.º 9
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            var expression      = this.FindMethod(binder, args);
            var restrictions    = BindingRestrictions.GetTypeRestriction(this.Expression, this.LimitType);
            var errorSuggestion = new DynamicMetaObject(expression, restrictions);

            return(binder.FallbackInvokeMember(this, args, errorSuggestion));
        }
Ejemplo n.º 10
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     if (!this.IsOverridden("TryInvokeMember"))
     {
         return(base.BindInvokeMember(binder, args));
     }
     DynamicProxyMetaObject <T> .Fallback fallback = (DynamicMetaObject e) => binder.FallbackInvokeMember(this, args, e);
     return(this.BuildCallMethodWithResult("TryInvokeMember", binder, DynamicProxyMetaObject <T> .GetArgArray(args), this.BuildCallMethodWithResult("TryGetMember", new DynamicProxyMetaObject <T> .GetBinderAdapter(binder), DynamicProxyMetaObject <T> .NoArgs, fallback(null), (DynamicMetaObject e) => binder.FallbackInvoke(e, args, null)), null));
 }
Ejemplo n.º 11
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            var retval = innerMetaObject.BindInvokeMember(binder, args);

            // call any parent object non-dynamic methods before trying wrapped object
            var newretval = binder.FallbackInvokeMember(this, args, retval);

            return(newretval);
        }
Ejemplo n.º 12
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            if (_runtime.TryInvokeMember == null)
            {
                return(base.BindInvokeMember(binder, args));
            }

            //
            // Generate a tree like:
            //
            // {
            //   object result;
            //   TryInvokeMember(payload, out result)
            //      ? result
            //      : TryGetMember(payload, out result)
            //          ? FallbackInvoke(result)
            //          : fallbackResult
            // }
            //
            // Then it calls FallbackInvokeMember with this tree as the
            // "error", giving the language the option of using this
            // tree or doing .NET binding.
            //
            DynamicMetaObject Fallback(DynamicMetaObject e) =>
            binder.FallbackInvokeMember(this, args, e);

            var call = BuildCallMethodWithResult(
                "TryInvokeMember",
                binder,
                GetArgArray(args),
                BuildCallMethodWithResult(
                    "TryGetMember",
                    new GetBinderAdapter(binder),
                    NoArgs,
                    Fallback(null),
                    e => binder.FallbackInvoke(e, args, null)
                    ),
                null
                );

            return(_dontFallbackFirst ? call : Fallback(call));
            //
            // See http://gist.github.com/386261 for why this is commented out
            //
            // IronRuby 1.0.0.0 on .NET 4.0.30319.1
            // Copyright (c) Microsoft Corporation. All rights reserved.
            //
            // >>> require 'Jayrock.Json'
            // => true
            // >>> o = Jayrock::Json::JsonObject.new
            // => {}
            // >>> o.foo = 123
            // => 123
            // >>> o.foo
            // (ir):1: undefined method `foo' for {"foo":123}:Jayrock::Json::JsonObject (NoMethodError)
        }
Ejemplo n.º 13
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            DynamicMetaObject messageSendMO;

            if (createMetaObjectToSendMessage(binder.Name, argArrayFor(args), out messageSendMO))
            {
                return(messageSendMO);
            }
            return(binder.FallbackInvokeMember(this, args, messageSendMO));
        }
Ejemplo n.º 14
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(BindGetOrInvokeMember(
                binder,
                binder.Name,
                binder.IgnoreCase,
                binder.FallbackInvokeMember(this, args),
                value => binder.FallbackInvoke(value, args, null)
                ));
 }
Ejemplo n.º 15
0
        public override DynamicMetaObject _0001(InvokeMemberBinder instance, DynamicMetaObject[] pol)
        {
            //Discarded unreachable code: IL_0002
            //IL_0003: Incompatible stack heights: 0 vs 1
            if (!CancelProperty("TryInvokeMember"))
            {
                return(base.BindInvokeMember(instance, pol));
            }
            MessageComposer messageComposer = (DynamicMetaObject P_0) => instance.FallbackInvokeMember(this, pol, P_0);

            return(CollectProperty("TryInvokeMember", instance, WorkerClientBridge <T> ._0001(pol), CollectProperty("TryGetMember", new ResolverPropertyStruct(instance), WorkerClientBridge <T> ._0001(), messageComposer(null), (DynamicMetaObject P_0) => instance.FallbackInvoke(P_0, pol, null)), null));
        }
Ejemplo n.º 16
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                // Generate a tree like:
                //
                // {
                //   object result;
                //   TryInvokeMember(payload, out result)
                //      ? result
                //      : TryGetMember(payload, out result)
                //          ? FallbackInvoke(result)
                //          : fallbackResult
                // }
                //
                // Then it calls FallbackInvokeMember with this tree as the
                // "error", giving the language the option of using this
                // tree or doing .NET binding.
                //
                DynamicMetaObject call = BuildCallMethodWithResult(
                    DynamicObject_TryInvokeMember,
                    binder,
                    GetExpressions(args),
                    BuildCallMethodWithResult <GetMemberBinder> (
                        DynamicObject_TryGetMember,
                        new GetBinderAdapter(binder),
                        s_noArgs,
                        binder.FallbackInvokeMember(this, args, null),
                        (GreedyMetaDynamic @this, GetMemberBinder ignored, DynamicMetaObject e) => binder.FallbackInvoke(e, args, null)
                        ),
                    null
                    );

                // JJA - we should handle these methods, too, otherwise we can't wrap the result in another dynamic object.
                if (binder.Name == "ToString" || binder.Name == "GetHashCode" || binder.Name == "GetType" || binder.Name == "Equals")
                {
                    return(call);
                }

                return(binder.FallbackInvokeMember(this, args, call));
            }
Ejemplo n.º 17
0
        public override DynamicMetaObject/*!*/ BindInvokeMember(InvokeMemberBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
            foreach (PythonType pt in Value.ResolutionOrder) {
                PythonTypeSlot dummy;
                if (pt.IsSystemType) {
                    return action.FallbackInvokeMember(this, args);
                } else if (
                    pt.TryResolveSlot(DefaultContext.DefaultCLS, action.Name, out dummy) ||
                    pt.IsOldClass) {
                    break;
                }
            }

            return BindingHelpers.GenericInvokeMember(action, null, this, args);
        }
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            if (!this.IsOverridden("TryInvokeMember"))
            {
                return(base.BindInvokeMember(binder, args));
            }
            Fallback <T>      fallback        = e => binder.FallbackInvokeMember((DynamicProxyMetaObject <T>) this, args, e);
            DynamicMetaObject errorSuggestion = this.BuildCallMethodWithResult("TryInvokeMember", binder, DynamicProxyMetaObject <T> .GetArgArray(args), this.BuildCallMethodWithResult("TryGetMember", new GetBinderAdapter <T>(binder), DynamicProxyMetaObject <T> .NoArgs, fallback(null), e => binder.FallbackInvoke(e, args, null)), null);

            if (!this._dontFallbackFirst)
            {
                return(fallback(errorSuggestion));
            }
            return(errorSuggestion);
        }
Ejemplo n.º 19
0
        // Token: 0x060015CA RID: 5578 RVA: 0x00067C5C File Offset: 0x00065E5C
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            if (!this.IsOverridden("TryInvokeMember"))
            {
                return(base.BindInvokeMember(binder, args));
            }
            Class_475 <T> .Fallback fallback          = (DynamicMetaObject e) => binder.FallbackInvokeMember(this, args, e);
            DynamicMetaObject       dynamicMetaObject = this.BuildCallMethodWithResult("TryInvokeMember", binder, Class_475 <T> .GetArgArray(args), this.BuildCallMethodWithResult("TryGetMember", new Class_475 <T> .GetBinderAdapter(binder), Class_475 <T> .NoArgs, fallback(null), (DynamicMetaObject e) => binder.FallbackInvoke(e, args, null)), null);

            if (!this._dontFallbackFirst)
            {
                return(fallback(dynamicMetaObject));
            }
            return(dynamicMetaObject);
        }
Ejemplo n.º 20
0
        /// <devdoc>
        /// Because we don't ComboBind over several MOs and operations, and no one is falling back to
        /// this function with MOs that have no values, we don't need to check HasValue. If we did
        /// check, and HasValue == False, then would defer to new InvokeMemberBinder.Defer().
        /// </devdoc>
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            var members = ReflectedType.GetMember(binder.Name, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public);

            if (members.Length == 1 && (members[0] is PropertyInfo || members[0] is FieldInfo))
            {
                // NEED TO TEST, should check for delegate value too
                var mem = members[0];
                throw new NotImplementedException();
                //return new DynamicMetaObject(
                //    Expression.Dynamic(
                //        new SymplInvokeBinder(new CallInfo(args.Length)),
                //        typeof(object),
                //        args.Select(a => a.Expression).AddFirst(
                //               Expression.MakeMemberAccess(this.Expression, mem)));

                // Don't test for EventInfos since we do nothing with them now.
            }
            else
            {
                // Get MethodInfos with param types that work for args. This works for except for
                // value args that need to pass to reftype params. We could detect that to be smarter
                // and then explicitly StrongBox the args.
                var res = Array.FindAll(members, member => member is MethodInfo m && m.GetParameters().Length == args.Length && RuntimeHelpers.ParametersMatchArguments(m.GetParameters(), args));

                if (res.Length == 0)
                {
                    // Sometimes when binding members on TypeModels the member is an instance member
                    // since the Type is an instance of Type. We fallback to the binder with the Type
                    // instance to see if it binds. The InvokeMemberBinder does handle this.
                    var typeMO = RuntimeHelpers.GetRuntimeTypeMoFromModel(this);
                    var result = binder.FallbackInvokeMember(typeMO, args, null);
                    return(result);
                }

                var meth = (MethodInfo)res[0];

                // True below means generate an instance restriction on the MO. We are only looking
                // at the members defined in this Type instance.
                var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(this, args, true);
                // restrictions and conversion must be done consistently.
                var callArgs = RuntimeHelpers.ConvertArguments(args, meth.GetParameters());
                return(new DynamicMetaObject(RuntimeHelpers.EnsureObjectResult(Expression.Call(meth, callArgs)), restrictions));
                // Could hve tried just letting expression.Call factory do the work, but if there is more
                // than one applicable method using just assignablefrom, expression.Call throws. It does
                // not pick a "most applicable" method or any method.
            }
        }
Ejemplo n.º 21
0
                }                 // func BindInvoke

                public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
                {
                    if (String.Compare(binder.Name, nameof(IsSmall), binder.IgnoreCase) == 0 ||
                        String.Compare(binder.Name, nameof(IsLarge), binder.IgnoreCase) == 0)
                    {
                        return(base.BindInvokeMember(binder, args));
                    }

                    if (!HasValue)
                    {
                        return(binder.Defer(this, args));
                    }

                    // redirect to the item
                    return(binder.FallbackInvokeMember(GetRawItemBinder(), args));
                }                 // func BindInvokeMember
Ejemplo n.º 22
0
        public override DynamicMetaObject /*!*/ BindInvokeMember(InvokeMemberBinder /*!*/ action, DynamicMetaObject /*!*/[] /*!*/ args)
        {
            foreach (PythonType pt in Value.ResolutionOrder)
            {
                if (pt.IsSystemType)
                {
                    return(action.FallbackInvokeMember(this, args));
                }
                else if (pt.TryResolveSlot(DefaultContext.DefaultCLS, action.Name, out _))
                {
                    break;
                }
            }

            return(BindingHelpers.GenericInvokeMember(action, null, this, args));
        }
Ejemplo n.º 23
0
        public override DynamicMetaObject BindInvokeMember(
            InvokeMemberBinder binder,
            DynamicMetaObject[] args
            )
        {
            if (!IsOverridden(nameof(DynamicProxy <T> .TryInvokeMember)))
            {
                return(base.BindInvokeMember(binder, args));
            }

            //
            // Generate a tree like:
            //
            // {
            //   object result;
            //   TryInvokeMember(payload, out result)
            //      ? result
            //      : TryGetMember(payload, out result)
            //          ? FallbackInvoke(result)
            //          : fallbackResult
            // }
            //
            // Then it calls FallbackInvokeMember with this tree as the
            // "error", giving the language the option of using this
            // tree or doing .NET binding.
            //
            Fallback fallback = e => binder.FallbackInvokeMember(this, args, e);

            return(BuildCallMethodWithResult(
                       nameof(DynamicProxy <T> .TryInvokeMember),
                       binder,
                       GetArgArray(args),
                       BuildCallMethodWithResult(
                           nameof(DynamicProxy <T> .TryGetMember),
                           new GetBinderAdapter(binder),
                           NoArgs,
                           fallback(null),
                           e => binder.FallbackInvoke(e, args, null)
                           ),
                       null
                       ));
        }
Ejemplo n.º 24
0
        public override DynamicMetaObject/*!*/ BindInvokeMember(InvokeMemberBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
            ParameterExpression tmp = Expression.Parameter(typeof(object));

            // first get the default binder value
            DynamicMetaObject fallback = action.FallbackInvokeMember(this, args);

            // then fallback w/ an error suggestion that does a late bound lookup.
            return action.FallbackInvokeMember(
                this,
                args,
                new DynamicMetaObject(
                    Ast.Block(
                        new[] { tmp },
                        Ast.Condition(
                            Ast.NotEqual(
                                Ast.Assign(
                                    tmp,
                                    Ast.Call(
                                        typeof(PythonOps).GetMethod("PythonFunctionGetMember"),
                                        AstUtils.Convert(
                                            Expression,
                                            typeof(PythonFunction)
                                        ),
                                        Expression.Constant(action.Name)
                                    )
                                ),
                                Ast.Constant(OperationFailed.Value)
                            ),
                            action.FallbackInvoke(
                                new DynamicMetaObject(tmp, BindingRestrictions.Empty),
                                args,
                                null
                            ).Expression,
                            AstUtils.Convert(fallback.Expression, typeof(object))
                        )
                    ),
                    BindingRestrictions.GetTypeRestriction(Expression, typeof(PythonFunction)).Merge(fallback.Restrictions)
                )
            );
        }
Ejemplo n.º 25
0
            // TODO: support for IgnoreCase in underlying ScriptScope APIs
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder action, DynamicMetaObject[] args)
            {
                var fallback = action.FallbackInvokeMember(this, args);
                var result   = Expression.Variable(typeof(object), "result");

                var fallbackInvoke = action.FallbackInvoke(new DynamicMetaObject(result, BindingRestrictions.Empty), args, null);

                return(new DynamicMetaObject(
                           Expression.Block(
                               new ParameterExpression[] { result },
                               Expression.Condition(
                                   Expression.Call(
                                       Expression.Convert(Expression, typeof(ScriptScope)),
                                       typeof(ScriptScope).GetMethod("TryGetVariable", new[] { typeof(string), typeof(object).MakeByRefType() }),
                                       Expression.Constant(action.Name),
                                       result
                                       ),
                                   Expression.Convert(fallbackInvoke.Expression, typeof(object)),
                                   Expression.Convert(fallback.Expression, typeof(object))
                                   )
                               ),
                           BindingRestrictions.Combine(args).Merge(BindingRestrictions.GetTypeRestriction(Expression, typeof(ScriptScope))).Merge(fallback.Restrictions)
                           ));
            }
Ejemplo n.º 26
0
 public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
 {
     return(_originalBinder.FallbackInvokeMember(target, args, errorSuggestion));
 }
Ejemplo n.º 27
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) {
     return DynamicTryGetValue(binder.Name, binder.IgnoreCase, 
         binder.FallbackInvokeMember(this, args).Expression,
         (tmp) => binder.FallbackInvoke(new DynamicMetaObject(tmp, BindingRestrictions.Empty), args, null).Expression
     );
 }
Ejemplo n.º 28
0
 public override MetaObject BindInvokeMember(InvokeMemberBinder binder, MetaObject[] args)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackInvokeMember(UnwrapSelf(), args));
 }
Ejemplo n.º 29
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) {
                if (IsOverridden("TryInvokeMember")) {
                    return CallMethodWithResult("TryInvokeMember", binder, GetArgArray(args), (e) => binder.FallbackInvokeMember(this, args, e));
                } else if (IsOverridden("TryGetMember")) {
                    // Generate a tree like:
                    //
                    // {
                    //   object result;
                    //   TryGetMember(payload, out result) ? FallbackInvoke(result) : fallbackResult
                    // }
                    //
                    // Then it calls FallbackInvokeMember with this tree as the
                    // "error", giving the language the option of using this
                    // tree or doing .NET binding.
                    //
                    return CallMethodWithResult(
                        "TryGetMember", new GetBinderAdapter(binder), NoArgs,
                        (e) => binder.FallbackInvokeMember(this, args, e),
                        (e) => binder.FallbackInvoke(e, args, null)
                    );
                }

                return base.BindInvokeMember(binder, args);
            }
Ejemplo n.º 30
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     return(binder.FallbackInvokeMember(UnwrapSelf(), args));
 }
Ejemplo n.º 31
0
            public override MetaObject /*!*/ BindInvokeMember(InvokeMemberBinder /*!*/ binder, params MetaObject /*!*/[] /*!*/ args)
            {
                var self = (IRubyObject)Value;

                return(RubyInvokeMemberBinder.TryBind(self.Class.Context, binder, this, args) ?? binder.FallbackInvokeMember(this, args));
            }
 /// <summary>
 /// Performs the binding of the dynamic invoke member operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="InvokeMemberBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackInvokeMember(this, args);
 }
Ejemplo n.º 33
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     // Whether or not to try the parent object first...
     return(binder.FallbackInvokeMember(this, args, innerMetaObject.BindInvokeMember(binder, args)));
     //return innerMetaObject.BindInvokeMember(binder, args);
 }
Ejemplo n.º 34
0
        // Because we don't ComboBind over several MOs and operations, and no one
        // is falling back to this function with MOs that have no values, we
        // don't need to check HasValue.  If we did check, and HasValue == False,
        // then would defer to new InvokeMemberBinder.Defer().
        //
        public override DynamicMetaObject BindInvokeMember(
            InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            var flags = BindingFlags.IgnoreCase | BindingFlags.Static |
                        BindingFlags.Public;
            var members = ReflType.GetMember(binder.Name, flags);

            if ((members.Length == 1) && (members[0] is PropertyInfo ||
                                          members[0] is FieldInfo))
            {
                // NEED TO TEST, should check for delegate value too
                var mem = members[0];
                throw new NotImplementedException();
                //return new DynamicMetaObject(
                //    Expression.Dynamic(
                //        new SymplInvokeBinder(new CallInfo(args.Length)),
                //        typeof(object),
                //        args.Select(a => a.Expression).AddFirst(
                //               Expression.MakeMemberAccess(this.Expression, mem)));

                // Don't test for eventinfos since we do nothing with them now.
            }
            else
            {
                // Get MethodInfos with right arg counts.
                var mi_mems = members.
                              Select(m => m as MethodInfo).
                              Where(m => m is MethodInfo &&
                                    ((MethodInfo)m).GetParameters().Length ==
                                    args.Length);
                // Get MethodInfos with param types that work for args.  This works
                // for except for value args that need to pass to reftype params.
                // We could detect that to be smarter and then explicitly StrongBox
                // the args.
                List <MethodInfo> res = new List <MethodInfo>();
                foreach (var mem in mi_mems)
                {
                    if (RuntimeHelpers.ParametersMatchArguments(
                            mem.GetParameters(), args))
                    {
                        res.Add(mem);
                    }
                }
                if (res.Count == 0)
                {
                    // Sometimes when binding members on TypeModels the member
                    // is an intance member since the Type is an instance of Type.
                    // We fallback to the binder with the Type instance to see if
                    // it binds.  The SymplInvokeMemberBinder does handle this.
                    var typeMO = RuntimeHelpers.GetRuntimeTypeMoFromModel(this);
                    var result = binder.FallbackInvokeMember(typeMO, args, null);
                    return(result);
                }
                // True below means generate an instance restriction on the MO.
                // We are only looking at the members defined in this Type instance.
                var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(
                    this, args, true);
                // restrictions and conversion must be done consistently.
                var callArgs =
                    RuntimeHelpers.ConvertArguments(
                        args, res[0].GetParameters());
                return(new DynamicMetaObject(
                           RuntimeHelpers.EnsureObjectResult(
                               Expression.Call(res[0], callArgs)),
                           restrictions));
                // Could hve tried just letting Expr.Call factory do the work,
                // but if there is more than one applicable method using just
                // assignablefrom, Expr.Call throws.  It does not pick a "most
                // applicable" method or any method.
            }
        }
Ejemplo n.º 35
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) {
     ContractUtils.RequiresNotNull(binder, nameof(binder));
     return binder.FallbackInvokeMember(UnwrapSelf(), args);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Performs the binding of the dynamic invoke member operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="InvokeMemberBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackInvokeMember(this, args));
 }
Ejemplo n.º 37
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackInvokeMember(UnwrapSelf(), args);
 }