Esempio n. 1
0
 /// <summary>
 /// 获取枚举值包含的位域值
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 public static IEnumerable <Enum> GetFlagEnums(this Enum e)
 {
     if (e.GetHashCode() == 0)
     {
         return(new Enum[0]);
     }
     return(e.GetFieldValues().Where(item => e.IsFlagContains(item)));
 }
Esempio n. 2
0
 /// <summary>
 /// 获取枚举类型所有字段的值
 /// </summary>
 /// <param name="e">枚举类型</param>
 /// <returns></returns>
 public static Enum[] GetFieldValues(this Enum e)
 {
     return(e.GetFieldValues <Enum>());
 }
Esempio n. 3
0
 /// <summary>
 /// 获取枚举类型所有字段值和对应的Dispaly特性名称
 /// </summary>
 /// <param name="e">枚举类型</param>
 /// <returns></returns>
 public static IEnumerable <KeyValuePair <Enum, string> > GetValueDisplays(this Enum e)
 {
     return(e.GetFieldValues().Select(item => new KeyValuePair <Enum, string>(item, item.GetFieldDisplay())));
 }
Esempio n. 4
0
 /// <summary>
 /// 获取枚举类型所有字段对应的Dispaly特性名称和说明
 /// </summary>
 /// <param name="e">枚举类型</param>
 /// <returns></returns>
 public static IEnumerable <KeyValuePair <string, string> > GetDisplays(this Enum e)
 {
     return(e.GetFieldValues().Select(item => item.GetAttribute <DisplayAttribute>()).Select(item => new KeyValuePair <string, string>(item.Name, item.Description)));
 }