示例#1
0
        /// <summary>
        /// 取属性成员
        /// </summary>
        /// <typeparam name="A">属性</typeparam>
        /// <typeparam name="T">类</typeparam>
        /// <returns></returns>
        public static List <ReportAttr> GetQuickDataBaseAttr <T>()
        {
            string            key    = "GetAllPAttr_" + typeof(ReportAttr).FullName + "_" + typeof(T).FullName;
            List <ReportAttr> result = (List <ReportAttr>)MemCach.GetCach(key);

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

            string tabName;

            object[] os = typeof(T).GetCustomAttributes(typeof(ReportAttr), true);
            if (os.Length > 0)
            {
                tabName = ((ReportAttr)os[0]).TableName;
            }
            else
            {
                tabName = typeof(T).Name;
            }

            result = new List <ReportAttr>();

            PropertyInfo[] propertyinfos = typeof(T).GetProperties();

            propertyinfos.ToList().ForEach(p =>
            {
                object[] obs = p.GetCustomAttributes(typeof(ReportAttr), true);
                if (obs.Length > 0)
                {
                    ReportAttr attr = (ReportAttr)obs[0];
                    attr.TableName  = tabName;
                    if (string.IsNullOrWhiteSpace(attr.Column))
                    {
                        attr.Column = p.Name;
                    }
                    if (string.IsNullOrWhiteSpace(attr.ColumnName))
                    {
                        attr.ColumnName = p.Name;
                    }
                    PropertyInfo pp = attr.GetType().GetProperty("Property");
                    if (pp != null)
                    {
                        pp.SetValue(attr, p, null);
                    }

                    result.Add((ReportAttr)obs[0]);
                }
            });

            MemCach.AddCach(key, result);
            return(result);
        }
示例#2
0
        /// <summary>
        /// 取属性成员
        /// </summary>
        /// <typeparam name="A">属性</typeparam>
        /// <typeparam name="T">类</typeparam>
        /// <returns></returns>
        public static List <A> GetAllPAttr <A, T>()
        {
            string   key    = "GetAllPAttr_" + typeof(A).FullName + "_" + typeof(T).FullName;
            List <A> result = (List <A>)MemCach.GetCach(key);

            if (result != null)
            {
                return(result);
            }
            result = new List <A>();

            PropertyInfo[] propertyinfos = typeof(T).GetProperties();

            propertyinfos.ToList().ForEach(p =>
            {
                object[] obs = p.GetCustomAttributes(typeof(A), true);
                if (obs.Length > 0)
                {
                    A attr          = (A)obs[0];
                    PropertyInfo pp = attr.GetType().GetProperty("Property");
                    if (pp != null)
                    {
                        pp.SetValue(attr, p, null);
                    }

                    result.Add((A)obs[0]);
                }
                //else
                //{
                //    A attr = new A();
                //    PropertyInfo pp = attr.GetType().GetProperty("Property");
                //    if (pp != null)
                //    {
                //        pp.SetValue(attr, p, null);
                //    }

                //    result.Add(attr);
                //}
            });

            MemCach.AddCach(key, result);
            return(result);
        }