20 lines
513 B
C#
20 lines
513 B
C#
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace Indotalent.ConfigBackEnd.Extensions;
|
|
|
|
public static class EnumExtension
|
|
{
|
|
public static string GetDescription(this Enum value)
|
|
{
|
|
var field = value.GetType().GetField(value.ToString());
|
|
if (field == null)
|
|
{
|
|
return value.ToString();
|
|
}
|
|
|
|
var attribute = field.GetCustomAttribute<DescriptionAttribute>();
|
|
|
|
return attribute == null ? value.ToString() : attribute.Description;
|
|
}
|
|
} |