22 lines
575 B
C#
22 lines
575 B
C#
using System;
|
|
using System.Reflection;
|
|
using BriarQueen.Data.Attributes;
|
|
|
|
namespace BriarQueen.Framework.Extensions
|
|
{
|
|
public static class EnumExtensions
|
|
{
|
|
public static string GetDisplayName(this Enum value)
|
|
{
|
|
var type = value.GetType();
|
|
var field = type.GetField(value.ToString());
|
|
|
|
if (field == null)
|
|
return value.ToString();
|
|
|
|
var attribute = field.GetCustomAttribute<DisplayNameAttribute>();
|
|
|
|
return attribute != null ? attribute.Name : value.ToString();
|
|
}
|
|
}
|
|
} |