public override object Get(string name, IScriptable start)
        {
            object result = base.Get (name, start);
            if (result != UniqueTag.NotFound || name == "Object")
                return result;

            if (m_Type.ClassAttribute != null) {
                CliMethodInfo mi = m_Type.GetFunctionsWithAttribute (name);
                if (mi != null)
                    return mi;
                return UniqueTag.NotFound;
            }

            // Compatiblity with Microsoft.JScript
            if (typeof (IReflect).IsAssignableFrom (m_Type.UnderlyingType)) {
                MemberInfo [] mis = ((IReflect)m_Object).GetMember (name, BindingFlags.Default);
                if (mis.Length > 0) {
                    if (mis [0] is PropertyInfo) {
                        return ((PropertyInfo)mis [0]).GetValue (m_Object, null);
                    }
                    else if (mis [0] is FieldInfo) {
                        return ((FieldInfo)mis [0]).GetValue (m_Object);
                    }
                    else {
                        return new CliMethodInfo (name, mis, null);
                    }
                }

                return UniqueTag.NotFound;
            }

            // 1. Search froperty
            PropertyInfo pi = m_Type.GetCachedProperty (name);
            if (pi != null) {
                if (!pi.CanRead)
                    throw Context.ReportRuntimeErrorById ("msg.undef.prop.read", name, ClassName);
                return pi.GetValue (m_Object, null);
            }

            // 2. Search field
            FieldInfo fi = m_Type.GetCachedField (name);
            if (fi != null) {
                if (!fi.IsPublic)
                    throw Context.ReportRuntimeErrorById ("msg.undef.prop.read", name, ClassName);
                return fi.GetValue (m_Object);
            }

            // 3. Search function
            CliMethodInfo nmi = m_Type.GetFunctions (name);
            if (nmi != null)
                return nmi;

            // 4. Indexer
            foreach (MethodInfo mi in m_Type.IndexGetter) {
                ParameterInfo [] pis = mi.GetParameters ();
                if (pis.Length == 1 && pis [0].ParameterType == typeof (string)) {
                    return mi.Invoke (m_Object, new object [] { name });
                }
            }

            // 4. Event
            EventInfo ei = m_Type.GetCachedEvent (name);
            if (ei != null) {
                CliEventInfo ncei = new CliEventInfo (ei);
                ncei.ParentScope = this;
                return ncei;
            }

            return UniqueTag.NotFound;
        }
Beispiel #2
0
        public override object Get(string name, IScriptable start)
        {
            object result = base.Get(name, start);

            if (result != UniqueTag.NotFound || name == "Object")
            {
                return(result);
            }

            if (m_Type.ClassAttribute != null)
            {
                CliMethodInfo mi = m_Type.GetFunctionsWithAttribute(name);
                if (mi != null)
                {
                    return(mi);
                }
                return(UniqueTag.NotFound);
            }

            // Compatiblity with Microsoft.JScript
            if (typeof(IReflect).IsAssignableFrom(m_Type.UnderlyingType))
            {
                MemberInfo [] mis = ((IReflect)m_Object).GetMember(name, BindingFlags.Default);
                if (mis.Length > 0)
                {
                    if (mis [0] is PropertyInfo)
                    {
                        return(((PropertyInfo)mis [0]).GetValue(m_Object, null));
                    }
                    else if (mis [0] is FieldInfo)
                    {
                        return(((FieldInfo)mis [0]).GetValue(m_Object));
                    }
                    else
                    {
                        return(new CliMethodInfo(name, mis, null));
                    }
                }

                return(UniqueTag.NotFound);
            }

            // 1. Search froperty
            PropertyInfo pi = m_Type.GetCachedProperty(name);

            if (pi != null)
            {
                if (!pi.CanRead)
                {
                    throw Context.ReportRuntimeErrorById("msg.undef.prop.read", name, ClassName);
                }
                return(pi.GetValue(m_Object, null));
            }

            // 2. Search field
            FieldInfo fi = m_Type.GetCachedField(name);

            if (fi != null)
            {
                if (!fi.IsPublic)
                {
                    throw Context.ReportRuntimeErrorById("msg.undef.prop.read", name, ClassName);
                }
                return(fi.GetValue(m_Object));
            }

            // 3. Search function
            CliMethodInfo nmi = m_Type.GetFunctions(name);

            if (nmi != null)
            {
                return(nmi);
            }

            // 4. Indexer
            foreach (MethodInfo mi in m_Type.IndexGetter)
            {
                ParameterInfo [] pis = mi.GetParameters();
                if (pis.Length == 1 && pis [0].ParameterType == typeof(string))
                {
                    return(mi.Invoke(m_Object, new object [] { name }));
                }
            }

            // 4. Event
            EventInfo ei = m_Type.GetCachedEvent(name);

            if (ei != null)
            {
                CliEventInfo ncei = new CliEventInfo(ei);
                ncei.ParentScope = this;
                return(ncei);
            }

            return(UniqueTag.NotFound);
        }