private static Dictionary <string, AopAttribute> GetAopAttributes(Type type)
        {
            Dictionary <string, AopAttribute> value = null;

            if (attrs.TryGetValue(type.FullName, out value) && value != null)
            {
                return(value);
            }
            value = new Dictionary <string, AopAttribute>();
            PropertyInfo[] properties = type.GetProperties();
            PropertyInfo[] array      = properties;
            foreach (PropertyInfo propertyInfo in array)
            {
                AopAttribute aopAttribute = new AopAttribute();
                aopAttribute.Method = propertyInfo.GetSetMethod();
                XmlElementAttribute[] array2 = propertyInfo.GetCustomAttributes(typeof(XmlElementAttribute), inherit: true) as XmlElementAttribute[];
                if (array2 != null && array2.Length != 0)
                {
                    aopAttribute.ItemName = array2[0].ElementName;
                }
                if (aopAttribute.ItemName == null)
                {
                    XmlArrayItemAttribute[] array3 = propertyInfo.GetCustomAttributes(typeof(XmlArrayItemAttribute), inherit: true) as XmlArrayItemAttribute[];
                    if (array3 != null && array3.Length != 0)
                    {
                        aopAttribute.ItemName = array3[0].ElementName;
                    }
                    XmlArrayAttribute[] array4 = propertyInfo.GetCustomAttributes(typeof(XmlArrayAttribute), inherit: true) as XmlArrayAttribute[];
                    if (array4 != null && array4.Length != 0)
                    {
                        aopAttribute.ListName = array4[0].ElementName;
                    }
                    if (aopAttribute.ListName == null)
                    {
                        continue;
                    }
                }
                if (propertyInfo.PropertyType.IsGenericType)
                {
                    Type[] genericArguments = propertyInfo.PropertyType.GetGenericArguments();
                    aopAttribute.ListType = genericArguments[0];
                }
                else
                {
                    aopAttribute.ItemType = propertyInfo.PropertyType;
                }
                value.Add(propertyInfo.Name + aopAttribute.ItemType + aopAttribute.ListType, aopAttribute);
            }
            attrs[type.FullName] = value;
            return(value);
        }
Beispiel #2
0
        private static Dictionary <string, AopAttribute> GetAopAttributes(Type type)
        {
            Dictionary <string, AopAttribute> tas = null;
            var inc = attrs.TryGetValue(type.FullName, out tas);

            if (inc && tas != null) // 从缓存中获取类属性元数据
            {
                return(tas);
            }
            tas = new Dictionary <string, AopAttribute>();

            var pis = type.GetProperties();

            foreach (var pi in pis)
            {
                var ta = new AopAttribute();
                ta.Method = pi.GetSetMethod();

                // 获取对象属性名称
                var xeas = pi.GetCustomAttributes(typeof(JsonPropertyAttribute), true) as JsonPropertyAttribute[];
                if (xeas != null && xeas.Length > 0)
                {
                    ta.ItemName = xeas[0].PropertyName;
                }

                // 获取属性类型
                if (pi.PropertyType.IsGenericType)
                {
                    var types = pi.PropertyType.GetGenericArguments();
                    ta.ListType = types[0];
                }
                else
                {
                    ta.ItemType = pi.PropertyType;
                }

                tas.Add(pi.Name + ta.ItemType + ta.ListType, ta);
            }

            attrs[type.FullName] = tas;
            return(tas);
        }
Beispiel #3
0
        private static Dictionary <string, AopAttribute> GetAopAttributes(Type type)
        {
            Dictionary <string, AopAttribute> tas = null;
            bool inc = attrs.TryGetValue(type.FullName, out tas);

            if (inc && tas != null) // 从缓存中获取类属性元数据
            {
                return(tas);
            }
            else // 创建新的类属性元数据缓存
            {
                tas = new Dictionary <string, AopAttribute>();
            }

            PropertyInfo[] pis = type.GetProperties();
            foreach (PropertyInfo pi in pis)
            {
                AopAttribute ta = new AopAttribute();
                ta.Method = pi.GetSetMethod();

                // 获取对象属性名称
                XmlElementAttribute[] xeas = pi.GetCustomAttributes(typeof(XmlElementAttribute), true) as XmlElementAttribute[];
                if (xeas != null && xeas.Length > 0)
                {
                    ta.ItemName = xeas[0].ElementName;
                }

                // 获取列表属性名称
                if (ta.ItemName == null)
                {
                    XmlArrayItemAttribute[] xaias = pi.GetCustomAttributes(typeof(XmlArrayItemAttribute), true) as XmlArrayItemAttribute[];
                    if (xaias != null && xaias.Length > 0)
                    {
                        ta.ItemName = xaias[0].ElementName;
                    }
                    XmlArrayAttribute[] xaas = pi.GetCustomAttributes(typeof(XmlArrayAttribute), true) as XmlArrayAttribute[];
                    if (xaas != null && xaas.Length > 0)
                    {
                        ta.ListName = xaas[0].ElementName;
                    }
                    if (ta.ListName == null)
                    {
                        continue;
                    }
                }

                // 获取属性类型
                if (pi.PropertyType.IsGenericType)
                {
                    Type[] types = pi.PropertyType.GetGenericArguments();
                    ta.ListType = types[0];
                }
                else
                {
                    ta.ItemType = pi.PropertyType;
                }

                tas.Add(pi.Name + ta.ItemType + ta.ListType, ta);
            }

            attrs[type.FullName] = tas;
            return(tas);
        }