Exemplo n.º 1
0
        internal List <Getters> GetGetters(Type type)
        {
            if (this._getterscache.ContainsKey(type))
            {
                return(this._getterscache[type]);
            }
            PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            List <Getters> list       = new List <Getters>();

            PropertyInfo[] array = properties;
            for (int i = 0; i < array.Length; i++)
            {
                PropertyInfo       propertyInfo  = array[i];
                JSON.GenericGetter genericGetter = JSON.CreateGetMethod(propertyInfo);
                if (genericGetter != null)
                {
                    list.Add(new Getters
                    {
                        Name   = propertyInfo.Name,
                        Getter = genericGetter
                    });
                }
            }
            this._getterscache.Add(type, list);
            return(list);
        }
Exemplo n.º 2
0
        internal List <Getters> GetGetters(Type type)
        {
            List <Getters> val = null;

            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            PropertyInfo[] props   = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                if (!p.CanWrite)
                {
                    continue;
                }

                JSON.GenericGetter g = CreateGetMethod(p);
                if (g != null)
                {
                    Getters gg = new Getters();
                    gg.Name         = p.Name;
                    gg.Getter       = g;
                    gg.propertyType = p.PropertyType;
                    getters.Add(gg);
                }
            }
            _getterscache.Add(type, getters);
            return(getters);
        }
Exemplo n.º 3
0
        internal List <Getters> GetGetters(Type type)
        {
            List <Getters> val = null;

            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            List <Getters> getters = new List <Getters>();

            //Property
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo p in props)
            {
                if (!p.CanWrite)
                {
                    continue;                                                         //TODO:?
                }
                object[] att = p.GetCustomAttributes(typeof(IgnoreAttribute), false); //这儿使用了XmlIgnoreAttribute标识
                if (att != null && att.Length > 0)
                {
                    continue;
                }

                JSON.GenericGetter g = CreateGetMethod(p);
                if (g != null)
                {
                    Getters gg = new Getters();
                    gg.Name         = p.Name;
                    gg.Getter       = g;
                    gg.propertyType = p.PropertyType;
                    getters.Add(gg);
                }
            }

            //Field
            FieldInfo[] fields = type.GetFields();
            foreach (FieldInfo f in fields)
            {
                object[] att = f.GetCustomAttributes(typeof(IgnoreAttribute), false); //这儿使用了XmlIgnoreAttribute标识
                if (att != null && att.Length > 0)
                {
                    continue;
                }

                JSON.GenericGetter g = CreateGetMethod(f);
                if (g != null)
                {
                    Getters gg = new Getters();
                    gg.Name         = f.Name;
                    gg.Getter       = g;
                    gg.propertyType = f.FieldType;
                    getters.Add(gg);
                }
            }

            _getterscache.Add(type, getters);
            return(getters);
        }
Exemplo n.º 4
0
        internal List <Getters> GetGetters(Type type)
        {
            List <Getters> val = null;

            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            PropertyInfo[] props   = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                if (!p.CanWrite && _params.ShowReadOnlyProperties == false && _params.EnableAnonymousTypes == false)
                {
                    continue;
                }

                object[] att = p.GetCustomAttributes(typeof(System.Xml.Serialization.XmlIgnoreAttribute), false);
                if (att != null && att.Length > 0)
                {
                    continue;
                }

                JSON.GenericGetter g = CreateGetMethod(p);
                if (g != null)
                {
                    Getters gg = new Getters();
                    gg.Name         = p.Name;
                    gg.Getter       = g;
                    gg.propertyType = p.PropertyType;
                    getters.Add(gg);
                }
            }

            FieldInfo[] fi = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (var f in fi)
            {
                object[] att = f.GetCustomAttributes(typeof(System.Xml.Serialization.XmlIgnoreAttribute), false);
                if (att != null && att.Length > 0)
                {
                    continue;
                }

                JSON.GenericGetter g = CreateGetField(type, f);
                if (g != null)
                {
                    Getters gg = new Getters();
                    gg.Name         = f.Name;
                    gg.Getter       = g;
                    gg.propertyType = f.FieldType;
                    getters.Add(gg);
                }
            }

            _getterscache.Add(type, getters);
            return(getters);
        }
Exemplo n.º 5
0
        internal List <Getters> GetGetters(Type type)
        {
            if (this._getterscache.ContainsKey(type))
            {
                return(this._getterscache[type]);
            }
            PropertyInfo[] properties  = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            List <Getters> gettersList = new List <Getters>();

            foreach (PropertyInfo propertyInfo in properties)
            {
                JSON.GenericGetter getMethod = JSON.CreateGetMethod(propertyInfo);
                if (getMethod != null)
                {
                    gettersList.Add(new Getters()
                    {
                        Name   = propertyInfo.Name,
                        Getter = getMethod
                    });
                }
            }
            this._getterscache.Add(type, gettersList);
            return(gettersList);
        }