/// <summary> /// 返回存储某类型的所有属性的集合。 /// </summary> /// <param name="objType">类型(类、接口、枚举等)</param> /// <returns>属性集合</returns> public static List <PropertyInfo> GetPropertyInfoList(Type objType) { string cachekey = string.Format("LST_{0}", objType.FullName); List <PropertyInfo> propList = (List <PropertyInfo>)DSCache.Get(cachekey); if (propList == null) { propList = new List <PropertyInfo>(); foreach (PropertyInfo objProperty in objType.GetProperties()) { propList.Add(objProperty); } DSCache.Insert(cachekey, propList); } return(propList); }
/// <summary> /// 返回存储某类型的所有属性和自定义属性(BindingFieldAttribute)的Dic。 /// </summary> /// <param name="objType">类型(类、接口、枚举等)</param> /// <returns>属性和自定义属性(BindingFieldAttribute)的集合</returns> public static Dictionary <string, PropertyInfo> GetPropertyInfoDic(Type objType) { string cachekey = string.Format("DIC_{0}", objType.FullName); Dictionary <string, PropertyInfo> propDic = (Dictionary <string, PropertyInfo>)DSCache.Get(cachekey); if (propDic == null) { propDic = new Dictionary <string, PropertyInfo>(); List <PropertyInfo> propList = GetPropertyInfoList(objType); foreach (PropertyInfo pi in propList) { object[] customAtts = pi.GetCustomAttributes(typeof(BindingFieldAttribute), true); if (customAtts != null && customAtts.Length > 0) { string key = ((BindingFieldAttribute)customAtts[0]).FieldName; if (string.IsNullOrEmpty(key)) { key = pi.Name.ToUpper(); } propDic.Add(key, pi); } } DSCache.Insert(cachekey, propDic); } return(propDic); }