Example #1
0
        /// <summary>
        /// 创建数据导入的列定义
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IList <ClassColumnInfo> Create(Type type)
        {
            var columnInfos = new List <ClassColumnInfo>();
            var properties  = type.GetProperties();
            var index       = 0;

            foreach (var property in properties)
            {
                var columnInfo = new ClassColumnInfo();
                columnInfo.Index = index;
                index++;
                columnInfo.Name = property.Name;
                var descriptionAttribute = property.GetCustomAttribute <DescriptionAttribute>();
                if (descriptionAttribute != null)
                {
                    columnInfo.Caption = descriptionAttribute.Description;
                }
                else
                {
                    var displayNameAttribute = property.GetCustomAttribute <DisplayNameAttribute>();
                    if (displayNameAttribute != null)
                    {
                        columnInfo.Caption = displayNameAttribute.DisplayName;
                    }
                }
                columnInfos.Add(columnInfo);
            }
            return(columnInfos);
        }
Example #2
0
        public virtual IList <ClassColumnInfo> GetColumnInfos()
        {
            var metas = ClassColumnInfo.Create(GetType());

            return(metas);
        }