GetMember() public method

public GetMember ( String name, BindingFlags bindingAttr ) : System.Reflection.MemberInfo[]
name String
bindingAttr BindingFlags
return System.Reflection.MemberInfo[]
        //Adds a list of classes to result. Superclasses always follow derived classes.

        internal void AddClassesExcluding(ClassScope excludedClass, String name, ArrayList result)
        {
            ArrayList eligibleClasses = new ArrayList();

            foreach (MemberInfo member in this.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (member is JSVariableField && ((JSVariableField)member).IsLiteral)
                {
                    Object val = ((JSVariableField)member).value;
                    if (val is ClassScope)
                    {
                        ClassScope csc = (ClassScope)val;
                        if (csc.name != member.Name)
                        {
                            continue;
                        }
                        if (excludedClass == null || !excludedClass.IsSameOrDerivedFrom(csc))
                        {
                            if (csc.GetMember(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).Length > 0)
                            {
                                eligibleClasses.Add(csc);
                            }
                        }
                    }
                }
            }
            if (eligibleClasses.Count == 0)
            {
                return;
            }
            ClassScope[] classes = new ClassScope[eligibleClasses.Count]; eligibleClasses.CopyTo(classes);
            Array.Sort(classes);
            result.AddRange(classes);
        }
        internal object EvaluateAsType()
        {
            object memberValue = this.rootObject.EvaluateAsWrappedNamespace(false).GetMemberValue(base.name);

            if ((memberValue != null) && !(memberValue is Microsoft.JScript.Missing))
            {
                return(memberValue);
            }
            object obj3       = null;
            Member rootObject = this.rootObject as Member;

            if (rootObject == null)
            {
                Lookup lookup = this.rootObject as Lookup;
                if (lookup == null)
                {
                    return(null);
                }
                ConstantWrapper wrapper = lookup.PartiallyEvaluate() as ConstantWrapper;
                if (wrapper == null)
                {
                    JSGlobalField member = lookup.member as JSGlobalField;
                    if ((member == null) || !member.IsLiteral)
                    {
                        return(null);
                    }
                    obj3 = member.value;
                }
                else
                {
                    obj3 = wrapper.value;
                }
            }
            else
            {
                obj3 = rootObject.EvaluateAsType();
            }
            ClassScope scope = obj3 as ClassScope;

            if (scope != null)
            {
                MemberInfo[] infoArray = scope.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (infoArray.Length != 0)
                {
                    JSMemberField field2 = infoArray[0] as JSMemberField;
                    if (((field2 != null) && field2.IsLiteral) && ((field2.value is ClassScope) && (field2.IsPublic || field2.IsAccessibleFrom(base.Engine.ScriptObjectStackTop()))))
                    {
                        return(field2.value);
                    }
                }
                return(null);
            }
            Type type = obj3 as Type;

            if (type != null)
            {
                return(type.GetNestedType(base.name));
            }
            return(null);
        }
        private void BindName(JSField inferenceTarget)
        {
            MemberInfo[] members = null;
            this.rootObject = this.rootObject.PartiallyEvaluate();
            IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget);

            if (this.rootObject is ConstantWrapper)
            {
                Object ob = Convert.ToObject2(this.rootObject.Evaluate(), this.Engine);
                if (ob == null)
                {
                    this.rootObject.context.HandleError(JSError.ObjectExpected);
                    return;
                }
                ClassScope csc = ob as ClassScope;
                Type       t   = ob as Type;
                if (csc != null || t != null)
                {
                    //object is a type. Look for static members on the type only. If none are found, look for instance members on type Type.
                    if (csc != null)
                    {
                        this.members = members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    else
                    {
                        this.members = members = t.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    if (members.Length > 0)
                    {
                        return;             //found a binding
                    }
                    //Look for instance members on type Type
                    this.members = members = Typeob.Type.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance);
                    return;
                }
                Namespace ns = ob as Namespace;
                if (ns != null)
                {
                    String fullname = ns.Name + "." + this.name;
                    csc = this.Engine.GetClass(fullname);
                    if (csc != null)
                    {
                        FieldAttributes attrs = FieldAttributes.Literal;
                        if ((csc.owner.attributes & TypeAttributes.Public) == 0)
                        {
                            attrs |= FieldAttributes.Private;
                        }
                        this.members = new MemberInfo[] { new JSGlobalField(null, this.name, csc, attrs) };
                        return;
                    }
                    else
                    {
                        t = this.Engine.GetType(fullname);
                        if (t != null)
                        {
                            this.members = new MemberInfo[] { t };
                            return;
                        }
                    }
                }
                else if (ob is MathObject || ob is ScriptFunction && !(ob is FunctionObject)) //It is a built in constructor function
                {
                    obType = (IReflect)ob;
                }
            }
            obType = this.ProvideWrapperForPrototypeProperties(obType);

            //Give up and go late bound if not enough is known about the object at compile time.
            if (obType == Typeob.Object && !this.isNonVirtual) //The latter provides for super in classes that extend System.Object
            {
                this.members = new MemberInfo[0];
                return;
            }

            Type ty = obType as Type;

            //Interfaces are weird, call a helper
            if (ty != null && ty.IsInterface)
            {
                this.members = JSBinder.GetInterfaceMembers(this.name, ty);
                return;
            }
            ClassScope cs = obType as ClassScope;

            if (cs != null && cs.owner.isInterface)
            {
                this.members = cs.owner.GetInterfaceMember(this.name);
                return;
            }

            //Now run up the inheritance chain until a member is found
            while (obType != null)
            {
                cs = obType as ClassScope;
                if (cs != null)
                {
                    //The FlattenHierachy flag here tells ClassScope to add in any overloads found on base classes
                    members = this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy);
                    if (members.Length > 0)
                    {
                        return;
                    }
                    obType = cs.GetSuperType();
                    continue;
                }
                ty = obType as Type;
                if (ty == null) //Dealing with the global scope via the this literal or with a built in object in fast mode
                {
                    this.members = obType.GetMember(this.name, BindingFlags.Public | BindingFlags.Instance);
                    return;
                }
                members = this.members = ty.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (members.Length > 0)
                {
                    MemberInfo mem = LateBinding.SelectMember(members);
                    if (mem == null)
                    {
                        //Found a method or methods. Need to add any overloads found in base classes.
                        //Do another lookup, this time with the DeclaredOnly flag cleared and asking only for methods
                        members = this.members = ty.GetMember(this.name, MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        if (members.Length == 0) //Dealing with an indexed property, ask again
                        {
                            this.members = ty.GetMember(this.name, MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        }
                    }
                    return;
                }
                obType = ty.BaseType;
            }
        }
        internal Object EvaluateAsType()
        {
            WrappedNamespace ns     = this.rootObject.EvaluateAsWrappedNamespace(false);
            Object           result = ns.GetMemberValue(this.name);

            if (result != null && !(result is Missing))
            {
                return(result);
            }
            Object ob   = null;
            Member root = this.rootObject as Member;

            if (root == null)
            {
                Lookup lookup = this.rootObject as Lookup;
                if (lookup == null)
                {
                    return(null);
                }
                ob = lookup.PartiallyEvaluate();
                ConstantWrapper cw = ob as ConstantWrapper;
                if (cw != null)
                {
                    ob = cw.value;
                }
                else
                {
                    JSGlobalField f = lookup.member as JSGlobalField;
                    if (f != null && f.IsLiteral)
                    {
                        ob = f.value;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                ob = root.EvaluateAsType();
            }
            ClassScope csc = ob as ClassScope;

            if (csc != null)
            {
                MemberInfo[] members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                if (members.Length == 0)
                {
                    return(null);
                }
                JSMemberField field = members[0] as JSMemberField;
                if (field == null || !field.IsLiteral || !(field.value is ClassScope) || !field.IsPublic && !field.IsAccessibleFrom(this.Engine.ScriptObjectStackTop()))
                {
                    return(null);
                }
                return(field.value);
            }
            Type t = ob as Type;

            if (t != null)
            {
                return(t.GetNestedType(this.name));
            }
            return(null);
        }
        internal void AddClassesExcluding(ClassScope excludedClass, string name, ArrayList result)
        {
            ArrayList list = new ArrayList();

            foreach (MemberInfo info in this.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
            {
                if ((info is JSVariableField) && ((JSVariableField)info).IsLiteral)
                {
                    object obj2 = ((JSVariableField)info).value;
                    if (obj2 is ClassScope)
                    {
                        ClassScope other = (ClassScope)obj2;
                        if (((other.name == info.Name) && ((excludedClass == null) || !excludedClass.IsSameOrDerivedFrom(other))) && (other.GetMember(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Length > 0))
                        {
                            list.Add(other);
                        }
                    }
                }
            }
            if (list.Count != 0)
            {
                ClassScope[] array = new ClassScope[list.Count];
                list.CopyTo(array);
                Array.Sort <ClassScope>(array);
                result.AddRange(array);
            }
        }
        private void BindName(JSField inferenceTarget)
        {
            MemberInfo[] mems = null;
            this.rootObject = this.rootObject.PartiallyEvaluate();
            IReflect obType = this.rootObjectInferredType = this.rootObject.InferType(inferenceTarget);

            if (this.rootObject is ConstantWrapper)
            {
                object obj2 = Microsoft.JScript.Convert.ToObject2(this.rootObject.Evaluate(), base.Engine);
                if (obj2 == null)
                {
                    this.rootObject.context.HandleError(JSError.ObjectExpected);
                    return;
                }
                ClassScope scope = obj2 as ClassScope;
                Type       type  = obj2 as Type;
                if ((scope != null) || (type != null))
                {
                    if (scope != null)
                    {
                        base.members = mems = scope.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    else
                    {
                        base.members = mems = type.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                    }
                    if (mems.Length <= 0)
                    {
                        base.members = mems = Typeob.Type.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance);
                    }
                    return;
                }
                Namespace namespace2 = obj2 as Namespace;
                if (namespace2 != null)
                {
                    string className = namespace2.Name + "." + base.name;
                    scope = base.Engine.GetClass(className);
                    if (scope != null)
                    {
                        FieldAttributes literal = FieldAttributes.Literal;
                        if ((scope.owner.attributes & TypeAttributes.Public) == TypeAttributes.AnsiClass)
                        {
                            literal |= FieldAttributes.Private;
                        }
                        base.members = new MemberInfo[] { new JSGlobalField(null, base.name, scope, literal) };
                        return;
                    }
                    type = base.Engine.GetType(className);
                    if (type != null)
                    {
                        base.members = new MemberInfo[] { type };
                        return;
                    }
                }
                else if ((obj2 is MathObject) || ((obj2 is ScriptFunction) && !(obj2 is FunctionObject)))
                {
                    obType = (IReflect)obj2;
                }
            }
            obType = this.ProvideWrapperForPrototypeProperties(obType);
            if ((obType == Typeob.Object) && !base.isNonVirtual)
            {
                base.members = new MemberInfo[0];
            }
            else
            {
                Type t = obType as Type;
                if ((t != null) && t.IsInterface)
                {
                    base.members = JSBinder.GetInterfaceMembers(base.name, t);
                }
                else
                {
                    ClassScope scope2 = obType as ClassScope;
                    if ((scope2 != null) && scope2.owner.isInterface)
                    {
                        base.members = scope2.owner.GetInterfaceMember(base.name);
                    }
                    else
                    {
                        while (obType != null)
                        {
                            scope2 = obType as ClassScope;
                            if (scope2 != null)
                            {
                                mems = base.members = obType.GetMember(base.name, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                                if (mems.Length > 0)
                                {
                                    return;
                                }
                                obType = scope2.GetSuperType();
                            }
                            else
                            {
                                t = obType as Type;
                                if (t == null)
                                {
                                    base.members = obType.GetMember(base.name, BindingFlags.Public | BindingFlags.Instance);
                                    return;
                                }
                                mems = base.members = t.GetMember(base.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                                if (mems.Length > 0)
                                {
                                    if (LateBinding.SelectMember(mems) == null)
                                    {
                                        mems = base.members = t.GetMember(base.name, MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                        if (mems.Length == 0)
                                        {
                                            base.members = t.GetMember(base.name, MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                        }
                                    }
                                    return;
                                }
                                obType = t.BaseType;
                            }
                        }
                    }
                }
            }
        }