/// <summary> /// 读取状态类型 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IList <ItemModel> GetConstStatus(string statusType) { IList <ItemModel> list = new List <ItemModel>(); ItemModel item = null; string description = string.Empty; string fullName = typeof(StatusHelper).Namespace + "." + statusType; Type t = Type.GetType(fullName); foreach (FieldInfo f in t.GetFields()) { CustFieldAttribute fieldAtt = Attribute.GetCustomAttribute(f, typeof(CustFieldAttribute)) as CustFieldAttribute; if (fieldAtt != null) { description = fieldAtt.Description; } item = new ItemModel() { Value = f.GetValue(null).ToString(), Text = description }; list.Add(item); } return(list); }
/// <summary> /// 读取状态类型 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IList <ItemModel> GetConstStatus <T>() where T : class { IList <ItemModel> list = new List <ItemModel>(); ItemModel item = null; string description = string.Empty; Type type = typeof(T); foreach (FieldInfo f in type.GetFields()) { CustFieldAttribute fieldlAtt = Attribute.GetCustomAttribute(f, typeof(CustFieldAttribute)) as CustFieldAttribute; if (fieldlAtt != null) { description = fieldlAtt.Description; } item = new ItemModel() { Value = f.GetValue(null).ToString(), Text = description }; list.Add(item); } return(list); }