Ejemplo n.º 1
0
        public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type)
        {
            if (Field.IsLiteral)
            {
                return(new DynamicMetaObject(
                           AstUtils.Constant(Field.GetValue(null), typeof(object)),
                           BindingRestrictions.Empty
                           ));
            }

            if (!IsStatic)
            {
                // return the field tracker...
                return(binder.ReturnMemberTracker(type, this));
            }

            if (Field.DeclaringType.ContainsGenericParameters())
            {
                return(null);
            }

            if (IsPublic && DeclaringType.IsPublic())
            {
                return(new DynamicMetaObject(
                           Ast.Convert(Ast.Field(null, Field), typeof(object)),
                           BindingRestrictions.Empty
                           ));
            }

            return(new DynamicMetaObject(
                       Ast.Call(
                           AstUtils.Convert(AstUtils.Constant(Field), typeof(FieldInfo)),
                           typeof(FieldInfo).GetMethod("GetValue"),
                           AstUtils.Constant(null)
                           ),
                       BindingRestrictions.Empty
                       ));
        }