当前位置: 代码迷 >> 综合 >> 获得枚举Display特性的Name
  详细解决方案

获得枚举Display特性的Name

热度:3   发布时间:2024-01-26 04:59:21.0
        public static string GetDisplayName(T obj){var type = typeof(T);var name = Enum.GetName(type, obj);var field = type.GetField(name);var attr = (DisplayAttribute)field.GetCustomAttribute(typeof(DisplayAttribute));return attr.Name ?? string.Empty;}

 

  相关解决方案