Exemplo n.º 1
0
        public static bool slowHasField(object obj, string field)
        {
            if ((obj == null))
            {
                return(false);
            }

            global::System.Type t = ((global::System.Type)((obj as global::System.Type)));
            global::System.Reflection.BindingFlags bf = default(global::System.Reflection.BindingFlags);
            if ((t == null))
            {
                string s = ((string)((obj as string)));
                if (!(string.Equals(s, null)))
                {
                    return(global::haxe.lang.StringRefl.handleGetField(s, field, false) != null);
                }

                t  = ((global::System.Type)(obj.GetType()));
                bf = ((global::System.Reflection.BindingFlags)((((global::System.Reflection.BindingFlags)((((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Instance)) | ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Public))))) | ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.FlattenHierarchy)))));
            }
            else
            {
                if ((t == ((global::System.Type)(typeof(string)))))
                {
                    return(string.Equals(field, "fromCharCode"));
                }

                obj = null;
                bf  = ((global::System.Reflection.BindingFlags)((((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Static)) | ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Public)))));
            }

            global::System.Reflection.MemberInfo[] mi = t.GetMember(((string)(field)), ((global::System.Reflection.BindingFlags)(bf)));
            if ((mi != null))
            {
                return((mi as global::System.Array).Length > 0);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public static object slowGetField(object obj, string field, bool throwErrors)
        {
            if ((obj == null))
            {
                if (throwErrors)
                {
                    throw new global::System.NullReferenceException(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Cannot access field \'", field), "\' of null."));
                }
                else
                {
                    return(null);
                }
            }

            global::System.Type t = ((global::System.Type)((obj as global::System.Type)));
            global::System.Reflection.BindingFlags bf = default(global::System.Reflection.BindingFlags);
            if ((t == null))
            {
                string s = ((string)((obj as string)));
                if (!(string.Equals(s, null)))
                {
                    return(global::haxe.lang.StringRefl.handleGetField(s, field, throwErrors));
                }

                t  = ((global::System.Type)(obj.GetType()));
                bf = ((global::System.Reflection.BindingFlags)((((global::System.Reflection.BindingFlags)((((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Instance)) | ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Public))))) | ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.FlattenHierarchy)))));
            }
            else
            {
                if (((t == ((global::System.Type)(typeof(string)))) && string.Equals(field, "fromCharCode")))
                {
                    return(new global::haxe.lang.Closure(typeof(global::haxe.lang.StringExt), field, 0));
                }

                obj = null;
                bf  = ((global::System.Reflection.BindingFlags)((((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Static)) | ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.Public)))));
            }

            global::System.Reflection.FieldInfo f = t.GetField(((string)(field)), ((global::System.Reflection.BindingFlags)(bf)));
            if ((f != null))
            {
                return(global::haxe.lang.Runtime.unbox(f.GetValue(((object)(obj)))));
            }
            else
            {
                global::System.Reflection.PropertyInfo prop = t.GetProperty(((string)(field)), ((global::System.Reflection.BindingFlags)(bf)));
                if ((prop == null))
                {
                    global::System.Reflection.MemberInfo[] m = t.GetMember(((string)(field)), ((global::System.Reflection.BindingFlags)(bf)));
                    if ((((m as global::System.Array).Length == 0) && ((string.Equals(field, "__get") || string.Equals(field, "__set")))))
                    {
                        m = t.GetMember(((string)(((string.Equals(field, "__get")) ? ("get_Item") : ("set_Item")))), ((global::System.Reflection.BindingFlags)(bf)));
                    }

                    if (((m as global::System.Array).Length > 0))
                    {
                        return(new global::haxe.lang.Closure((((obj != null)) ? (obj) : ((object)(t))), field, 0));
                    }
                    else
                    {
                        if (t.IsCOMObject)
                        {
                            try {
                                return(t.InvokeMember(((string)(field)), ((global::System.Reflection.BindingFlags)(global::System.Reflection.BindingFlags.GetProperty)), default(global::System.Reflection.Binder), ((object)(obj)), ((object[])(new object[0]))));
                            }
                            catch (global::System.Exception e) {
                                global::haxe.lang.Exceptions.exception = e;
                            }
                        }

                        if (throwErrors)
                        {
                            throw global::haxe.lang.HaxeException.wrap(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Cannot access field \'", field), "\'."));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                return(global::haxe.lang.Runtime.unbox(prop.GetValue(((object)(obj)), default(object[]))));
            }
        }