FallbackGetMember() public method

Performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
public FallbackGetMember ( DynamicMetaObject target ) : DynamicMetaObject
target DynamicMetaObject The target of the dynamic get member operation.
return DynamicMetaObject
            public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
                var binderDefault = binder.FallbackGetMember(this);

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

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

                return binder.FallbackGetMember(this, dynamicSuggestion);
            }
示例#2
0
        public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
            ContractUtils.RequiresNotNull(binder, "binder");
            string name = binder.Name;

            if (name == _info.Name) {
                name = "TypeLibDesc";
            } else if (name != "Guid" &&
                name != "Name" &&
                name != "VersionMajor" &&
                name != "VersionMinor") {

                return binder.FallbackGetMember(this);
            }

            return new DynamicMetaObject(
                Expression.Convert(
                    Expression.Property(
                        AstUtils.Convert(Expression, typeof(ComTypeLibInfo)),
                        typeof(ComTypeLibInfo).GetProperty(name)
                    ),
                    typeof(object)
                ),
                ComTypeLibInfoRestrictions(this)
            );
        }
示例#3
0
        public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
        {
            if (IsOverridden("TryGetMember"))
            {
                return(CallMethodWithResult("TryGetMember", binder, NoArgs, (e) => binder.FallbackGetMember(this, e)));
            }

            return(base.BindGetMember(binder));
        }
示例#4
0
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     ContractUtils.RequiresNotNull(binder, nameof(binder));
     return(BindGetOrInvokeMember(
                binder,
                binder.Name,
                binder.IgnoreCase,
                binder.FallbackGetMember(this),
                null
                ));
 }
示例#5
0
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     ArgumentNullException.ThrowIfNull(binder);
     return(BindGetOrInvokeMember(
                binder,
                binder.Name,
                binder.IgnoreCase,
                binder.FallbackGetMember(this),
                null
                ));
 }
示例#6
0
            public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
            {
                Fallback fallback = null;

                if (!this.IsOverridden("TryGetMember"))
                {
                    return(base.BindGetMember(binder));
                }
                if (fallback == null)
                {
                    fallback = e => binder.FallbackGetMember(this, e);
                }
                return(this.CallMethodWithResult("TryGetMember", binder, NoArgs, fallback));
            }
 /// <summary>
 /// Performs the binding of the dynamic get member operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="GetMemberBinder"/> that represents the details of the dynamic operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackGetMember(this));
 }
            public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
                if (IsOverridden("TryGetMember")) {
                    return CallMethodWithResult("TryGetMember", binder, NoArgs, (e) => binder.FallbackGetMember(this, e));
                }

                return base.BindGetMember(binder);
            }
示例#9
0
文件: Sympl.cs 项目: TerabyteX/main
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
     var flags = BindingFlags.IgnoreCase | BindingFlags.Static | 
                 BindingFlags.Public;
     // consider BindingFlags.Instance if want to return wrapper for
     // inst members that is callable.
     var members = ReflType.GetMember(binder.Name, flags);
     if (members.Length == 1) {
         return new DynamicMetaObject(
             // We always access static members for type model objects, so the
             // first argument in MakeMemberAccess should be null.
             RuntimeHelpers.EnsureObjectResult(
                 Expression.MakeMemberAccess(
                     null,
                     members[0])),
             // Don't need restriction test for name since this
             // rule is only used where binder is used, which is
             // only used in sites with this binder.Name.
             this.Restrictions.Merge(
                 BindingRestrictions.GetInstanceRestriction(
                     this.Expression,
                     this.Value)
             )
         );
     } else {
         return binder.FallbackGetMember(this);
     }
 }
示例#10
0
 /// <summary>
 /// Performs the binding of the dynamic get member operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="GetMemberBinder"/> that represents the details of the dynamic operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindGetMember(GetMemberBinder binder) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackGetMember(this);
 }
示例#11
0
 public override DynamicMetaObject/*!*/ BindGetMember(GetMemberBinder/*!*/ binder) {
     var self = (IRubyObject)Value;
     return RubyGetMemberBinder.TryBind(self.Class.Context, binder, this) ?? binder.FallbackGetMember(this);
 }
示例#12
0
文件: Scope.cs 项目: bclubb/ironruby
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
     var tmp = Expression.Parameter(typeof(object));
     return new DynamicMetaObject(
         Expression.Block(
             new[] { tmp },
             Expression.Condition(
                 Expression.NotEqual(
                     Expression.Assign(
                         tmp,
                         Expression.Invoke(
                             Expression.Constant(new Func<object, SymbolId, object>(AttributesAdapter.TryGetMember)),
                             Expression,
                             Expression.Constant(SymbolTable.StringToId(binder.Name))
                         )
                     ),
                     Expression.Constant(_getFailed)
                 ),
                 tmp,
                 Expression.Convert(binder.FallbackGetMember(this).Expression, typeof(object))
             )
         ),
         GetRestrictions()
     );
 }
示例#13
0
            public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
            {
                var prop = _type.GetProperty(binder.Name);

                if (prop != null && prop.Methods != null && prop.CompiledMethods == null)
                    prop.CompiledMethods = _type.MakeCompileMethods(binder.Name);

                if (prop != null && prop.CompiledMethods != null)
                {
                    var ret = prop.CompiledMethods(this);
                    if (ret != null)
                        return ret;
                }

                if (prop != null && prop.Getters != null)
                {
                    foreach (var getter in prop.Getters)
                    {
                        var ret = getter(this);
                        if (ret != null)
                        {
                            return ret;
                        }
                    }
                }

                ITotemProperty totemProp;
                if(_type._customProperties.TryGetValue(binder.Name, out totemProp))
                {
                    return new DynamicMetaObject(
                        AstUtils.SimpleCallHelper(
                            Expression.Constant(totemProp, typeof(ITotemProperty)),
                            typeof(ITotemProperty).GetMethod("Get"),
                            Expression
                        ),
                        BindingRestrictions.GetTypeRestriction(Expression, LimitType)
                    );
                }

                DynamicMetaObject result;
                if (_type.HandleGetMember(binder, this, out result))
                    return result;

                var fallback = binder.FallbackGetMember(this, result);
                BindingRestrictions restrictions = fallback.Restrictions.Merge(BindingRestrictions.GetTypeRestriction(Expression, LimitType));

                return new DynamicMetaObject(
                    AssertImplemented(
                        Expression.Call(
                            Expression.Constant(_type, typeof(TotemType)),
                            TotemType.GetMissingPropertyInfo,
                            Expression,
                            Expression.Constant(binder.Name, typeof(string))
                        ),
                        fallback.Expression
                    ),
                    restrictions
                );
            }
示例#14
0
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     return binder.FallbackGetMember(UnwrapSelf());
 }
示例#15
0
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackGetMember(UnwrapSelf());
 }
示例#16
0
 /// <summary>
 /// Performs the binding of the dynamic get member operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="GetMemberBinder"/> that represents the details of the dynamic operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     ArgumentNullException.ThrowIfNull(binder);
     return(binder.FallbackGetMember(this));
 }
示例#17
0
            public override DynamicMetaObject BindGetMember
                    (GetMemberBinder binder)
            {
                var self = this.Expression;
                var bag = (FastNBag)base.Value;

                int index = bag.GetFastIndex(binder.Name);

                Expression target;

                // If match found in fast array:
                if (index != -1)
                {
                    // Fetch result from fast array.
                    target =
                        Expression.Call(
                            Expression.Convert(self, typeof(FastNBag)),
                            typeof(FastNBag).GetMethod("GetFastValue"),
                            Expression.Constant(index)
                        );
                }
                // Else, if no match found in fast array, but fast array is full:
                else if (bag.fastTable.Count == bag.fastCount)
                {
                    // Fetch result from dictionary.
                    var keyExpr = Expression.Constant(binder.Name);
                    var valueExpr = Expression.Variable(typeof(object));

                    var dictCheckExpr =
                        Expression.Call(
                            Expression.Convert(self, typeof(FastNBag)),
                            typeof(FastNBag).GetMethod("TryGetValue"),
                            keyExpr,
                            valueExpr
                        );
                    var dictFailExpr =
                        Expression.Block(
                            binder.FallbackGetMember(this).Expression,
                            Expression.Default(typeof(object))
                        );

                    target =
                        Expression.Block(
                            new[] { valueExpr },
                            Expression.Condition(
                                dictCheckExpr,
                                valueExpr,
                                dictFailExpr
                            )
                        );
                }
                // Else, no match found in fast array, fast array is not yet full:
                else
                {
                    // Fail binding, but only until fast array is updated.
                    var versionCheckExpr =
                        Expression.Call(
                            Expression.Convert(self, typeof(FastNBag)),
                            typeof(FastNBag).GetMethod("CheckVersion"),
                            Expression.Constant(bag.Version)
                        );
                    var versionMatchExpr =
                        binder.FallbackGetMember(this).Expression;
                    var updateExpr =
                        binder.GetUpdateExpression(versionMatchExpr.Type);

                    target =
                        Expression.Condition(
                            versionCheckExpr,
                            versionMatchExpr,
                            updateExpr
                        );
                }

                var restrictions = BindingRestrictions
                                       .GetInstanceRestriction(self, bag);

                return new DynamicMetaObject(target, restrictions);
            }
示例#18
0
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     return DynamicTryGetMember(binder.Name,
         binder.FallbackGetMember(this).Expression,
         (tmp) => tmp
     );
 }
 public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     Fallback fallback = null;
     if (!this.IsOverridden("TryGetMember"))
     {
         return base.BindGetMember(binder);
     }
     if (fallback == null)
     {
         fallback = e => binder.FallbackGetMember(this, e);
     }
     return this.CallMethodWithResult("TryGetMember", binder, NoArgs, fallback);
 }
示例#20
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (this.UseFallbackMethod)
            {
                DynamicMetaObject target = new DynamicMetaObject(Expression.Parameter(this.GetType()), BindingRestrictions.Empty);
                DynamicMetaObject errorSuggestion = null;

                if (this.UseErrorSuggestion)
                {
                    errorSuggestion = new DynamicMetaObject(Expression.Throw(Expression.Constant(new TestDynamicObjectException())), BindingRestrictions.Empty);
                }

                DynamicMetaObject metaObj = binder.FallbackGetMember(target, errorSuggestion);
                Expression<Action> lambda = Expression.Lambda<Action>(metaObj.Expression, new ParameterExpression[] { });
                lambda.Compile().Invoke();
            }

            return _values.TryGetValue(binder.Name, out result);
        }
示例#21
0
            public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
                ContractUtils.RequiresNotNull(binder, "binder");
                DynamicMetaObject memberValue = GetDynamicMetaObjectForMember(
                    binder.Name, 
                    binder.IgnoreCase,
                    binder.FallbackGetMember(this)
                );

                return AddDynamicTestAndDefer(
                    binder,
                    new DynamicMetaObject[] { this },
                    Value.Class,
                    null,
                    memberValue
                );
            }
示例#22
0
 public override DynamicMetaObject BindGetMember( GetMemberBinder binder )
 {
     return binder.FallbackGetMember( _baseMetaObject,
                                      AddTypeRestrictions( _metaObject.BindGetMember( binder ) ) );
 }