123456789101112131415161718192021222324252627282930313233343536373839 |
- using DevExpress.XtraEditors;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.Repostory.Model;
- namespace DxHelper
- {
- /// <summary>
- /// 枚举扩展
- /// </summary>
- public static class EnumExtension
- {
- /// <summary>
- /// 获取枚举描述
- /// </summary>
- /// <param name="enumType">枚举类型</param>
- /// <returns></returns>
- public static string GetEnumDisplayName(this Enum enumType)
- {
- try
- {
- Type type = enumType.GetType();
- var field = type.GetField(Enum.GetName(type, enumType));
- string displayName = field.GetCustomAttribute<DisplayAttribute>().Name;
- return displayName;
- }
- catch
- {
- return string.Empty;
- }
-
- }
- }
- }
|