EvaluateAsType() private method

private EvaluateAsType ( ) : Object
return Object
        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);
        }
Example #2
0
        internal override AST PartiallyEvaluate()
        {
            if (this.recursive)
            {
                if (!(this.expression is ConstantWrapper))
                {
                    this.expression = new ConstantWrapper(Typeob.Object, base.context);
                }
                return(this);
            }
            Member expression = this.expression as Member;

            if (expression != null)
            {
                object obj2 = expression.EvaluateAsType();
                if (obj2 != null)
                {
                    this.expression = new ConstantWrapper(obj2, expression.context);
                    return(this);
                }
            }
            this.recursive  = true;
            this.expression = this.expression.PartiallyEvaluate();
            this.recursive  = false;
            if (!(this.expression is TypeExpression))
            {
                Type c = null;
                if (this.expression is ConstantWrapper)
                {
                    object obj3 = this.expression.Evaluate();
                    if (obj3 == null)
                    {
                        this.expression.context.HandleError(JSError.NeedType);
                        this.expression = new ConstantWrapper(Typeob.Object, base.context);
                        return(this);
                    }
                    c = Globals.TypeRefs.ToReferenceContext(obj3.GetType());
                    Binding.WarnIfObsolete(obj3 as Type, this.expression.context);
                }
                else if (this.expression.OkToUseAsType())
                {
                    c = Globals.TypeRefs.ToReferenceContext(this.expression.Evaluate().GetType());
                }
                else
                {
                    this.expression.context.HandleError(JSError.NeedCompileTimeConstant);
                    this.expression = new ConstantWrapper(Typeob.Object, this.expression.context);
                    return(this);
                }
                if ((c == null) || (((c != Typeob.ClassScope) && (c != Typeob.TypedArray)) && !Typeob.Type.IsAssignableFrom(c)))
                {
                    this.expression.context.HandleError(JSError.NeedType);
                    this.expression = new ConstantWrapper(Typeob.Object, this.expression.context);
                }
            }
            return(this);
        }
        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);
        }
Example #4
0
        internal override AST PartiallyEvaluate()
        {
            if (this.recursive)
            {
                if (this.expression is ConstantWrapper)
                {
                    return(this);
                }
                this.expression = new ConstantWrapper(Typeob.Object, this.context);
                return(this);
            }
            Member member = this.expression as Member;

            if (member != null)
            {
                //Dealing with a qualified name. See if there is a type/class with such a name, bypassing normal scope lookup.
                Object type = member.EvaluateAsType();
                if (type != null)
                {
                    this.expression = new ConstantWrapper(type, member.context);
                    return(this);
                }
            }
            this.recursive  = true;
            this.expression = this.expression.PartiallyEvaluate();
            this.recursive  = false;
            if (this.expression is TypeExpression)
            {
                return(this);
            }
            //Make sure that the expression represents a Type
            Type t = null;

            if (this.expression is ConstantWrapper)
            {
                Object val = this.expression.Evaluate();
                if (val == null)
                {
                    this.expression.context.HandleError(JSError.NeedType);
                    this.expression = new ConstantWrapper(Typeob.Object, this.context);
                    return(this);
                }
                t = val.GetType();
                Binding.WarnIfObsolete(val as Type, this.expression.context);
            }
            else
            {
                if (this.expression.OkToUseAsType())
                {
                    t = this.expression.Evaluate().GetType();
                }
                else
                {
                    this.expression.context.HandleError(JSError.NeedCompileTimeConstant);
                    this.expression = new ConstantWrapper(Typeob.Object, this.expression.context);
                    return(this);
                }
            }
            if (t == null || (t != Typeob.ClassScope && t != Typeob.TypedArray && !typeof(Type).IsAssignableFrom(t)))
            {
                this.expression.context.HandleError(JSError.NeedType);
                this.expression = new ConstantWrapper(Typeob.Object, this.expression.context);
            }
            return(this);
        }