示例#1
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
     );
 }
示例#2
0
        /// <summary>
        /// Transforms an invoke member into a Python GetMember/Invoke.  The caller should
        /// verify that the given attribute is not resolved against a normal .NET class
        /// before calling this.  If it is a normal .NET member then a fallback InvokeMember
        /// is preferred.
        /// </summary>
        internal static DynamicMetaObject/*!*/ GenericInvokeMember(InvokeMemberBinder/*!*/ action, ValidationInfo valInfo, DynamicMetaObject target, DynamicMetaObject/*!*/[]/*!*/ args) {
            if (target.NeedsDeferral()) {
                return action.Defer(args);
            }

            return AddDynamicTestAndDefer(action, 
                action.FallbackInvoke(
                    new DynamicMetaObject(
                        Binders.Get(
                            BinderState.GetCodeContext(action),
                            BinderState.GetBinderState(action),
                            typeof(object),
                            action.Name,
                            target.Expression
                        ),
                        BindingRestrictionsHelpers.GetRuntimeTypeRestriction(target)
                    ),
                    args,
                    null
                ),
                args,
                valInfo
            );
        }
        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)
                )
            );
        }
示例#4
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));
            }
            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);
            }
示例#6
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            if (!IsOverridden("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);
            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));
        }
示例#7
0
 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(this.BindGetOrInvokeMember(binder, binder.Name, binder.IgnoreCase, binder.FallbackInvokeMember(this, args), value => binder.FallbackInvoke(value, args, null)));
 }
示例#8
0
 public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
 {
     return(_originalBinder.FallbackInvoke(target, args, errorSuggestion));
 }
示例#9
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);
            DynamicMetaObject dynamicMetaObject           = 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);

            if (!this._dontFallbackFirst)
            {
                return(fallback(dynamicMetaObject));
            }
            return(dynamicMetaObject);
        }
        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);
        }