20 lines
612 B
C#
20 lines
612 B
C#
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace adas_core.Domain.Utils;
|
|
|
|
public static class EnumUtils
|
|
{
|
|
public static string GetDescription(Enum value)
|
|
{
|
|
var enumMember = value.GetType().GetMember(value.ToString()).FirstOrDefault();
|
|
var descriptionAttribute =
|
|
enumMember == null
|
|
? null
|
|
: enumMember.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;
|
|
return
|
|
descriptionAttribute == null
|
|
? value.ToString()
|
|
: descriptionAttribute.Description;
|
|
}
|
|
} |