コード例 #1
0
        internal Getters[] GetGetters(Type type, JSONParameters param)
        {
            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 && param.ShowReadOnlyProperties == false)
                {
                    continue;
                }
                if (param.IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in param.IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                GenericGetter g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (var f in fi)
            {
                if (param.IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in param.IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }

                GenericGetter g = CreateGetField(type, f);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = f.Name
                    });
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
コード例 #2
0
        internal Getters[] GetGetters(Type type, bool ShowReadOnlyProperties, List <Type> IgnoreAttributes)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            //bool isAnonymous = IsAnonymousType(type);

            var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;

            //if (ShowReadOnlyProperties)
            //    bf |= BindingFlags.NonPublic;
            PropertyInfo[] props   = type.GetProperties(bf);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                if (p.GetIndexParameters().Length > 0)
                {// Property is an indexer
                    continue;
                }
                if (!p.CanWrite && (ShowReadOnlyProperties == false))//|| isAnonymous == false))
                {
                    continue;
                }
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                GenericGetter g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name, lcName = p.Name.ToLower()
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(bf);
            foreach (var f in fi)
            {
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                if (f.IsLiteral == false)
                {
                    GenericGetter g = CreateGetField(type, f);
                    if (g != null)
                    {
                        getters.Add(new Getters {
                            Getter = g, Name = f.Name, lcName = f.Name.ToLower()
                        });
                    }
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }