예제 #1
0
        /// <summary>
        /// 获取 T 对像的所有属性
        /// </summary>
        private Dictionary <string, ColumnPropertyInfo> GetObjectColumnPropertyList()
        {
            Dictionary <string, ColumnPropertyInfo> result = new Dictionary <string, ColumnPropertyInfo>();
            Type t = typeof(T);

            if (t != null)
            {
                PropertyInfo[] piList = t.GetProperties();
                foreach (var pi in piList)
                {
                    if (!pi.PropertyType.IsGenericType)
                    {
                        ExcelColumnInfoAttribute ci = pi.GetCustomAttribute <ExcelColumnInfoAttribute>();

                        if (null == ci)
                        {
                            continue;
                        }

                        ColumnPropertyInfo colPropInfo = new ColumnPropertyInfo(pi, ci);

                        result.Add(ci.ColumnName, colPropInfo);
                    }
                }
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 获取 T 对像的所有属性
        /// </summary>
        private Dictionary <string, ColumnPropertyInfo> GetObjectColumnPropertyList()
        {
            var modelName = typeof(T).Name;

            if (!MyExcelModels.ContainsKey(modelName))
            {
                Dictionary <string, ColumnPropertyInfo> result = new Dictionary <string, ColumnPropertyInfo>();
                Type t = typeof(T);
                if (t != null)
                {
                    PropertyInfo[] piList = t.GetProperties();
                    foreach (var pi in piList)
                    {
                        if (!pi.PropertyType.IsGenericType)
                        {
                            ExcelColumnInfoAttribute ci = pi.GetCustomAttribute <ExcelColumnInfoAttribute>();

                            if (null == ci)
                            {
                                continue;
                            }

                            ColumnPropertyInfo colPropInfo = new ColumnPropertyInfo(pi, ci);

                            result.Add(pi.Name, colPropInfo);
                        }
                    }
                }
                MyExcelModels.GetOrAdd(modelName, result);
                return(result);
            }
            else
            {
                return(MyExcelModels[modelName]);
            }
        }
예제 #3
0
 public ColumnPropertyInfo(PropertyInfo property, ExcelColumnInfoAttribute excelColumnInfo)
 {
     Property        = property;
     ExcelColumnInfo = excelColumnInfo;
 }