Files
Aperio_Control_Centre/Aperio_Control_Centre/Extensions/EnumExtension.cs
2023-09-27 09:34:20 +02:00

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;
}
}
}