22 lines
645 B
C#
22 lines
645 B
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Reflection;
|
|
|
|
namespace Aperio_Control_Centre.Extensions
|
|
{
|
|
public static class EnumExtension
|
|
{
|
|
public static string GetDisplayName(this Enum enumValue)
|
|
{
|
|
if (enumValue == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(enumValue), "GetDisplayName EnumHelper, enumValue is null.");
|
|
}
|
|
|
|
return enumValue.GetType().GetMember(enumValue.ToString())
|
|
.First()
|
|
.GetCustomAttribute<DisplayAttribute>()
|
|
.Name;
|
|
}
|
|
}
|
|
}
|