Пример #1
0
        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;
            }
        }
Пример #2
0
        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;
                            }
                        }
                    }
                }
            }
        }