mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-18 00:21:33 -07:00
23 lines
599 B
C#
23 lines
599 B
C#
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace Bloxstrap.Extensions
|
|
{
|
|
internal static class TEnumEx
|
|
{
|
|
public static string? GetDescription<TEnum>(this TEnum e)
|
|
{
|
|
string? enumName = e?.ToString();
|
|
if (enumName == null)
|
|
return null;
|
|
|
|
FieldInfo? field = e?.GetType().GetField(enumName);
|
|
if (field == null)
|
|
return null;
|
|
|
|
DescriptionAttribute? attribute = field.GetCustomAttribute<DescriptionAttribute>();
|
|
return attribute?.Description;
|
|
}
|
|
}
|
|
}
|