SelectMember() static private method

static private SelectMember ( MemberInfo mems ) : MemberInfo
mems System.Reflection.MemberInfo
return System.Reflection.MemberInfo
示例#1
0
 internal override void SetMemberValue(string name, object value)
 {
     MemberInfo[] member = this.GetMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
     if (member.Length == 0)
     {
         if (VsaEngine.executeForJSEE)
         {
             throw new JScriptException(JSError.UndefinedIdentifier, new Context(new DocumentContext("", null), name));
         }
         FieldInfo info = this.AddField(name);
         if (info != null)
         {
             info.SetValue(this, value);
         }
     }
     else
     {
         MemberInfo info2 = LateBinding.SelectMember(member);
         if (info2 == null)
         {
             throw new JScriptException(JSError.AssignmentToReadOnly);
         }
         LateBinding.SetMemberValue(this, name, value, info2, member);
     }
 }
示例#2
0
        internal override void SetMemberValue(String name, Object value)
        {
            MemberInfo[] members = this.GetMember(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
            if (members.Length == 0)
            {
                // We do not want to create expando fields on the global object when assigning to an undefined
                // variable in the debugger.
                if (VsaEngine.executeForJSEE)
                {
                    throw new JScriptException(JSError.UndefinedIdentifier, new Context(new DocumentContext("", null), name));
                }
                FieldInfo field = this.AddField(name);
                if (field != null)
                {
                    field.SetValue(this, value);
                }
                return;
            }
            MemberInfo m = LateBinding.SelectMember(members);

            if (m == null)
            {
                throw new JScriptException(JSError.AssignmentToReadOnly);
            }
            LateBinding.SetMemberValue(this, name, value, m, members);
        }
示例#3
0
 internal virtual Object GetMemberValue(String name)
 {
     MemberInfo[] members = this.GetMember(name, BindingFlags.Instance | BindingFlags.Public);
     if (members.Length == 0)
     {
         return(Missing.Value);
     }
     return(LateBinding.GetMemberValue(this, name, LateBinding.SelectMember(members), members));
 }
示例#4
0
 internal virtual object GetMemberValue(string name)
 {
     MemberInfo[] member = this.GetMember(name, BindingFlags.Public | BindingFlags.Instance);
     if (member.Length == 0)
     {
         return(Microsoft.JScript.Missing.Value);
     }
     return(LateBinding.GetMemberValue(this, name, LateBinding.SelectMember(member), member));
 }
        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;
            }
        }
示例#6
0
 //This routine combines a GetField/GetProperty (with expando) and a subsequent SetValue operation.
 //It is used when the Field/Property cannot be cached. It is overridden by JSObject and GlobalScope to provide expando
 internal virtual void SetMemberValue(String name, Object value)
 {
     MemberInfo[] members = this.GetMember(name, BindingFlags.Instance | BindingFlags.Public);
     LateBinding.SetMemberValue(this, name, value, LateBinding.SelectMember(members), members);
 }
        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;
                            }
                        }
                    }
                }
            }
        }
示例#8
0
 internal virtual void SetMemberValue(string name, object value)
 {
     MemberInfo[] member = this.GetMember(name, BindingFlags.Public | BindingFlags.Instance);
     LateBinding.SetMemberValue(this, name, value, LateBinding.SelectMember(member), member);
 }