12 lines
348 B
C#
12 lines
348 B
C#
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
public class EnumDisplayHelper
|
|
{
|
|
public static string DisplayName(object item)
|
|
{
|
|
if (item == null) return "";
|
|
var field = item.GetType().GetField(item.ToString());
|
|
return field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
|
}
|
|
} |