using System.ComponentModel;
using System.Reflection;
namespace adas_core.Domain.Utils;
///
/// Provides static utility methods for working with types.
///
public static class EnumUtils
{
///
/// Retrieves the human-readable description for an enumeration value by inspecting its .
/// Falls back to the enum's string representation when no description attribute is defined on the member.
///
/// The enumeration value whose description should be obtained.
/// The description text from the if present; otherwise, the string representation of the enum value.
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;
}
}