GetGetMethod() static private method

static private GetGetMethod ( PropertyInfo prop, bool nonPublic ) : MethodInfo
prop System.Reflection.PropertyInfo
nonPublic bool
return System.Reflection.MethodInfo
        public override String ToString()
        {
            Type       t    = this.members[0].DeclaringType;
            MethodInfo meth = (t == null ? null :  t.GetMethod(this.name + " source"));

            if (meth == null)
            {
                StringBuilder result    = new StringBuilder();
                bool          firstTime = true;
                foreach (MemberInfo mem in this.members)
                {
                    if (mem is MethodInfo || (mem is PropertyInfo && JSProperty.GetGetMethod((PropertyInfo)mem, false) != null))
                    {
                        if (!firstTime)
                        {
                            result.Append("\n");
                        }
                        else
                        {
                            firstTime = false;
                        }
                        result.Append(mem.ToString());
                    }
                }
                if (result.Length > 0)
                {
                    return(result.ToString());
                }
                return("function " + this.name + "() {\n    [native code]\n}");
            }
            return((String)meth.Invoke(null, null));
        }
Beispiel #2
0
        public override string ToString()
        {
            Type       declaringType = this.members[0].DeclaringType;
            MethodInfo info          = (declaringType == null) ? null : declaringType.GetMethod(base.name + " source");

            if (info != null)
            {
                return((string)info.Invoke(null, null));
            }
            StringBuilder builder = new StringBuilder();
            bool          flag    = true;

            foreach (MemberInfo info2 in this.members)
            {
                if ((info2 is MethodInfo) || ((info2 is PropertyInfo) && (JSProperty.GetGetMethod((PropertyInfo)info2, false) != null)))
                {
                    if (!flag)
                    {
                        builder.Append("\n");
                    }
                    else
                    {
                        flag = false;
                    }
                    builder.Append(info2.ToString());
                }
            }
            if (builder.Length > 0)
            {
                return(builder.ToString());
            }
            return("function " + base.name + "() {\n    [native code]\n}");
        }
Beispiel #3
0
        private static MemberInfo[] GetAndWrapMember(IReflect reflect, Object namedItem, String name, BindingFlags bindingAttr)
        {
            PropertyInfo property = reflect.GetProperty(name, bindingAttr);

            if (property != null)
            {
                MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
                if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic))
                {
                    MethodInfo method = reflect.GetMethod(name, bindingAttr);
                    if (method != null && !method.IsStatic)
                    {
                        MemberInfo[] propMethods = new MemberInfo[1];
                        propMethods[0] = new JSWrappedPropertyAndMethod(property, method, namedItem);
                        return(propMethods);
                    }
                }
            }
            MemberInfo[] members = reflect.GetMember(name, bindingAttr);
            if (members != null && members.Length > 0)
            {
                return(ScriptObject.WrapMembers(members, namedItem));
            }
            return(null);
        }
Beispiel #4
0
 internal static MethodInfo GetGetMethod(PropertyInfo prop, bool nonPublic)
 {
     if (prop != null)
     {
         JSProperty property = prop as JSProperty;
         if (property != null)
         {
             return(property.GetGetMethod(nonPublic));
         }
         MethodInfo getMethod = prop.GetGetMethod(nonPublic);
         if (getMethod != null)
         {
             return(getMethod);
         }
         Type declaringType = prop.DeclaringType;
         if (declaringType == null)
         {
             return(null);
         }
         Type baseType = declaringType.BaseType;
         if (baseType == null)
         {
             return(null);
         }
         getMethod = prop.GetGetMethod(nonPublic);
         if (getMethod == null)
         {
             return(null);
         }
         BindingFlags @public = BindingFlags.Public;
         if (getMethod.IsStatic)
         {
             @public |= BindingFlags.FlattenHierarchy | BindingFlags.Static;
         }
         else
         {
             @public |= BindingFlags.Instance;
         }
         if (nonPublic)
         {
             @public |= BindingFlags.NonPublic;
         }
         string name = prop.Name;
         prop = null;
         try
         {
             prop = baseType.GetProperty(name, @public, null, null, new Type[0], null);
         }
         catch (AmbiguousMatchException)
         {
         }
         if (prop != null)
         {
             return(GetGetMethod(prop, nonPublic));
         }
     }
     return(null);
 }
Beispiel #5
0
        public override MethodInfo GetGetMethod(bool nonPublic)
        {
            MethodInfo meth = JSProperty.GetGetMethod(this.property, nonPublic);

            if (meth == null)
            {
                return(null);
            }
            return(new JSWrappedMethod(meth, this.obj));
        }
Beispiel #6
0
        internal static MemberInfo WrapMember(MemberInfo member, Object obj)
        {
            switch (member.MemberType)
            {
            case MemberTypes.Field:
                FieldInfo field = (FieldInfo)member;
                if (field.IsStatic || field.IsLiteral)
                {
                    return(field);
                }
                else if (!(field is JSWrappedField))
                {
                    return(new JSWrappedField(field, obj));
                }
                else
                {
                    return(field);
                }

            case MemberTypes.Method:
                MethodInfo method = (MethodInfo)member;
                if (method.IsStatic)
                {
                    return(method);
                }
                else if (!(method is JSWrappedMethod))
                {
                    return(new JSWrappedMethod(method, obj));
                }
                else
                {
                    return(method);
                }

            case MemberTypes.Property:
                PropertyInfo property = (PropertyInfo)member;
                if (property is JSWrappedProperty)
                {
                    return(property);
                }
                MethodInfo getMethod = JSProperty.GetGetMethod(property, true);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, true);
                if ((getMethod == null || getMethod.IsStatic) && (setMethod == null || setMethod.IsStatic))
                {
                    return(property);
                }
                else
                {
                    return(new JSWrappedProperty(property, obj));
                }

            default:
                return(member);
            }
        }
Beispiel #7
0
        internal static MemberInfo WrapMember(MemberInfo member, object obj)
        {
            MemberTypes memberType = member.MemberType;

            if (memberType != MemberTypes.Field)
            {
                if (memberType != MemberTypes.Method)
                {
                    if (memberType != MemberTypes.Property)
                    {
                        return(member);
                    }
                    PropertyInfo prop = (PropertyInfo)member;
                    if (prop is JSWrappedProperty)
                    {
                        return(prop);
                    }
                    MethodInfo getMethod = JSProperty.GetGetMethod(prop, true);
                    MethodInfo setMethod = JSProperty.GetSetMethod(prop, true);
                    if (((getMethod == null) || getMethod.IsStatic) && ((setMethod == null) || setMethod.IsStatic))
                    {
                        return(prop);
                    }
                    return(new JSWrappedProperty(prop, obj));
                }
            }
            else
            {
                FieldInfo field = (FieldInfo)member;
                if (field.IsStatic || field.IsLiteral)
                {
                    return(field);
                }
                if (field is JSWrappedField)
                {
                    return(field);
                }
                return(new JSWrappedField(field, obj));
            }
            MethodInfo method = (MethodInfo)member;

            if (method.IsStatic)
            {
                return(method);
            }
            if (method is JSWrappedMethod)
            {
                return(method);
            }
            return(new JSWrappedMethod(method, obj));
        }
        internal override object GetMemberValue(string name)
        {
            FieldInfo field = (FieldInfo)this.NameTable[name];

            if ((field == null) && this.isASubClass)
            {
                field = this.subClassIR.GetField(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (field != null)
                {
                    if (field.DeclaringType == Typeob.ScriptObject)
                    {
                        return(Microsoft.JScript.Missing.Value);
                    }
                }
                else
                {
                    PropertyInfo property = this.subClassIR.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
                    if ((property != null) && !property.DeclaringType.IsAssignableFrom(Typeob.JSObject))
                    {
                        return(JSProperty.GetGetMethod(property, false).Invoke(this, BindingFlags.SuppressChangeType, null, null, null));
                    }
                    try
                    {
                        MethodInfo method = this.subClassIR.GetMethod(name, BindingFlags.Public | BindingFlags.Static);
                        if (method != null)
                        {
                            Type declaringType = method.DeclaringType;
                            if (((declaringType != Typeob.JSObject) && (declaringType != Typeob.ScriptObject)) && (declaringType != Typeob.Object))
                            {
                                return(new BuiltinFunction(this, method));
                            }
                        }
                    }
                    catch (AmbiguousMatchException)
                    {
                    }
                }
            }
            if (field != null)
            {
                return(field.GetValue(this));
            }
            if (base.parent != null)
            {
                return(base.parent.GetMemberValue(name));
            }
            return(Microsoft.JScript.Missing.Value);
        }
        internal override void CheckIfOKToUseInSuperConstructorCall()
        {
            FieldInfo member = base.member as FieldInfo;

            if (member != null)
            {
                if (!member.IsStatic)
                {
                    base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
            }
            else
            {
                MethodInfo getMethod = base.member as MethodInfo;
                if (getMethod != null)
                {
                    if (!getMethod.IsStatic)
                    {
                        base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                    }
                }
                else
                {
                    PropertyInfo prop = base.member as PropertyInfo;
                    if (prop != null)
                    {
                        getMethod = JSProperty.GetGetMethod(prop, true);
                        if ((getMethod != null) && !getMethod.IsStatic)
                        {
                            base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                        }
                        else
                        {
                            getMethod = JSProperty.GetSetMethod(prop, true);
                            if ((getMethod != null) && !getMethod.IsStatic)
                            {
                                base.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                            }
                        }
                    }
                }
            }
        }
Beispiel #10
0
        internal override void CheckIfOKToUseInSuperConstructorCall()
        {
            FieldInfo f = this.member as FieldInfo;

            if (f != null)
            {
                if (!f.IsStatic)
                {
                    this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
                return;
            }
            MethodInfo m = this.member as MethodInfo;

            if (m != null)
            {
                if (!m.IsStatic)
                {
                    this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
                return;
            }
            PropertyInfo p = this.member as PropertyInfo;

            if (p != null)
            {
                m = JSProperty.GetGetMethod(p, true);
                if (m != null && !m.IsStatic)
                {
                    this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                }
                else
                {
                    m = JSProperty.GetSetMethod(p, true);
                    if (m != null && !m.IsStatic)
                    {
                        this.context.HandleError(JSError.NotAllowedInSuperConstructorCall);
                    }
                }
            }
        }
Beispiel #11
0
        internal static Object GetValue(PropertyInfo prop, Object obj, Object[] index)
        {
            JSProperty jsprop = prop as JSProperty;

            if (jsprop != null)
            {
                return(jsprop.GetValue(obj, BindingFlags.ExactBinding, null, index, null));
            }
            JSWrappedProperty jswrappedprop = prop as JSWrappedProperty;

            if (jswrappedprop != null)
            {
                return(jswrappedprop.GetValue(obj, BindingFlags.ExactBinding, null, index, null));
            }
            MethodInfo meth = JSProperty.GetGetMethod(prop, false);

            if (meth != null)
            {
                return(meth.Invoke(obj, BindingFlags.ExactBinding, null, index, null));
            }
            throw new MissingMethodException();
        }
        private static MemberInfo[] GetAndWrapMember(IReflect reflect, object namedItem, string name, BindingFlags bindingAttr)
        {
            PropertyInfo property = reflect.GetProperty(name, bindingAttr);

            if (property != null)
            {
                MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
                MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
                if (((getMethod != null) && !getMethod.IsStatic) || ((setMethod != null) && !setMethod.IsStatic))
                {
                    MethodInfo method = reflect.GetMethod(name, bindingAttr);
                    if ((method != null) && !method.IsStatic)
                    {
                        return(new MemberInfo[] { new JSWrappedPropertyAndMethod(property, method, namedItem) });
                    }
                }
            }
            MemberInfo[] member = reflect.GetMember(name, bindingAttr);
            if ((member != null) && (member.Length > 0))
            {
                return(ScriptObject.WrapMembers(member, namedItem));
            }
            return(null);
        }
Beispiel #13
0
        public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
        {
            FieldInfo info = (FieldInfo)base.name_table[name];

            if (info != null)
            {
                return(new MemberInfo[] { info });
            }
            bool         flag   = false;
            ScriptObject parent = base.parent;

            while (parent is FunctionScope)
            {
                FunctionScope scope = (FunctionScope)parent;
                flag = scope.isMethod && !scope.isStatic;
                JSLocalField field = (JSLocalField)scope.name_table[name];
                if (field == null)
                {
                    parent = parent.GetParent();
                }
                else
                {
                    if (field.IsLiteral && !(field.value is FunctionObject))
                    {
                        return(new MemberInfo[] { field });
                    }
                    JSLocalField field2 = new JSLocalField(field.Name, this, base.field_table.Count, Microsoft.JScript.Missing.Value)
                    {
                        outerField = field,
                        debugOn    = field.debugOn
                    };
                    if ((!field2.debugOn && this.owner.funcContext.document.debugOn) && scope.owner.funcContext.document.debugOn)
                    {
                        field2.debugOn = Array.IndexOf <string>(scope.owner.formal_parameters, field.Name) >= 0;
                    }
                    field2.isDefined    = field.isDefined;
                    field2.debuggerName = "outer." + field2.Name;
                    if (field.IsLiteral)
                    {
                        field2.attributeFlags |= FieldAttributes.Literal;
                        field2.value           = field.value;
                    }
                    this.AddOuterScopeField(name, field2);
                    if (this.ProvidesOuterScopeLocals[parent] == null)
                    {
                        this.ProvidesOuterScopeLocals[parent] = parent;
                    }
                    ((FunctionScope)parent).mustSaveStackLocals = true;
                    return(new MemberInfo[] { field2 });
                }
            }
            if ((parent is ClassScope) && flag)
            {
                MemberInfo[] member = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly);
                int          length = member.Length;
                bool         flag2  = false;
                for (int i = 0; i < length; i++)
                {
                    MethodInfo   info3;
                    PropertyInfo info4;
                    MemberInfo   info2      = member[i];
                    MemberTypes  memberType = info2.MemberType;
                    if (memberType != MemberTypes.Field)
                    {
                        if (memberType == MemberTypes.Method)
                        {
                            goto Label_029E;
                        }
                        if (memberType == MemberTypes.Property)
                        {
                            goto Label_02C7;
                        }
                    }
                    else
                    {
                        info = (FieldInfo)info2;
                        if (info.IsLiteral)
                        {
                            JSMemberField field3 = info as JSMemberField;
                            if (((field3 != null) && (field3.value is ClassScope)) && !((ClassScope)field3.value).owner.IsStatic)
                            {
                                flag2 = true;
                            }
                        }
                        if (!info.IsStatic && !info.IsLiteral)
                        {
                            member[i] = new JSClosureField(info);
                            flag2     = true;
                        }
                    }
                    continue;
Label_029E:
                    info3 = (MethodInfo)info2;
                    if (!info3.IsStatic)
                    {
                        member[i] = new JSClosureMethod(info3);
                        flag2     = true;
                    }
                    continue;
Label_02C7:
                    info4 = (PropertyInfo)info2;
                    MethodInfo getMethod = JSProperty.GetGetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default);
                    MethodInfo setMethod = JSProperty.GetSetMethod(info4, (bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default);
                    bool       flag3     = false;
                    if ((getMethod != null) && !getMethod.IsStatic)
                    {
                        flag3     = true;
                        getMethod = new JSClosureMethod(getMethod);
                    }
                    if ((setMethod != null) && !setMethod.IsStatic)
                    {
                        flag3     = true;
                        setMethod = new JSClosureMethod(setMethod);
                    }
                    if (flag3)
                    {
                        member[i] = new JSClosureProperty(info4, getMethod, setMethod);
                        flag2     = true;
                    }
                }
                if (flag2)
                {
                    this.GiveOuterFunctionsTheBadNews();
                }
                if (length > 0)
                {
                    return(member);
                }
            }
            if ((bindingAttr & BindingFlags.DeclaredOnly) != BindingFlags.Default)
            {
                return(new MemberInfo[0]);
            }
            return(parent.GetMember(name, bindingAttr));
        }
Beispiel #14
0
        public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr)
        {
            FieldInfo field = (FieldInfo)(this.name_table[name]);

            if (field != null)
            {
                return new MemberInfo[] { field }
            }
            ;
            bool         nestedInInstanceMethod = false;
            ScriptObject parent = this.parent;

            //Treat locals of outer functions as if they were locals of this function
            while (parent is FunctionScope)
            {
                FunctionScope fscope = (FunctionScope)parent;

                nestedInInstanceMethod = fscope.isMethod && !fscope.isStatic;
                JSLocalField lfield = (JSLocalField)fscope.name_table[name];
                if (lfield == null)
                {
                    parent = parent.GetParent();
                    continue;
                }
                if (lfield.IsLiteral && !(lfield.value is FunctionObject))
                {
                    return new MemberInfo[] { lfield }
                }
                ;
                JSLocalField f = new JSLocalField(lfield.Name, this, this.field_table.Count, Missing.Value);
                f.outerField = lfield;
                f.debugOn    = lfield.debugOn;
                if (!f.debugOn && this.owner.funcContext.document.debugOn && fscope.owner.funcContext.document.debugOn)
                {
                    //Check to see it is off because outer field is a parameter
                    f.debugOn = Array.IndexOf(fscope.owner.formal_parameters, lfield.Name) >= 0;
                }
                f.isDefined    = lfield.isDefined;
                f.debuggerName = "outer" + "." + f.Name;
                if (lfield.IsLiteral)
                {
                    f.attributeFlags |= FieldAttributes.Literal;
                    f.value           = lfield.value;
                }
                this.AddOuterScopeField(name, f);
                if (this.ProvidesOuterScopeLocals[parent] == null)
                {
                    this.ProvidesOuterScopeLocals[parent] = parent;
                }
                ((FunctionScope)parent).mustSaveStackLocals = true;
                return(new MemberInfo[] { f });
            }
            if (parent is ClassScope && nestedInInstanceMethod)
            {
                //return class members as if they were local to the function. It is more convenient to wrap up instance members
                //at this stage than it is to figure out later that a special case is involved.
                MemberInfo[] members     = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly);
                int          n           = members.Length;
                bool         giveBadNews = false;
                for (int i = 0; i < n; i++)
                {
                    MemberInfo member = members[i];
                    switch (member.MemberType)
                    {
                    case MemberTypes.Field:
                        field = (FieldInfo)member;
                        if (field.IsLiteral)
                        {
                            JSMemberField mfield = field as JSMemberField;
                            if (mfield != null && mfield.value is ClassScope && !((ClassScope)mfield.value).owner.IsStatic)
                            {
                                giveBadNews = true;
                            }
                        }
                        if (!field.IsStatic && !field.IsLiteral)
                        {
                            members[i]  = new JSClosureField(field);
                            giveBadNews = true;
                        }
                        break;

                    case MemberTypes.Method:
                        MethodInfo meth = (MethodInfo)member;
                        if (!meth.IsStatic)
                        {
                            members[i]  = new JSClosureMethod(meth);
                            giveBadNews = true;
                        }
                        break;

                    case MemberTypes.Property:
                        PropertyInfo prop      = (PropertyInfo)member;
                        MethodInfo   getMeth   = JSProperty.GetGetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0);
                        MethodInfo   setMeth   = JSProperty.GetSetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0);
                        bool         nonStatic = false;
                        if (getMeth != null && !getMeth.IsStatic)
                        {
                            nonStatic = true;
                            getMeth   = new JSClosureMethod(getMeth);
                        }
                        if (setMeth != null && !setMeth.IsStatic)
                        {
                            nonStatic = true;
                            setMeth   = new JSClosureMethod(setMeth);
                        }
                        if (nonStatic)
                        {
                            members[i]  = new JSClosureProperty(prop, getMeth, setMeth);
                            giveBadNews = true;
                        }
                        break;
                    }
                }
                if (giveBadNews)
                {
                    this.GiveOuterFunctionsTheBadNews();        //They have to create explicit stack frames
                }
                if (n > 0)
                {
                    return(members);
                }
            }
            if ((bindingAttr & BindingFlags.DeclaredOnly) != 0)
            {
                return(new MemberInfo[0]);
            }
            return(parent.GetMember(name, bindingAttr));
        }