FFMpegCore/FFMpegCore.Extensions.Downloader/Extensions/EnumExtensions.cs
2025-01-27 22:22:47 -05:00

21 lines
646 B
C#

using System.ComponentModel;
namespace FFMpegCore.Extensions.Downloader.Extensions;
internal static class EnumExtensions
{
public static string GetDescription(this Enum enumValue)
{
var field = enumValue.GetType().GetField(enumValue.ToString());
if (field == null)
return enumValue.ToString();
var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)
{
return attribute.Description;
}
return enumValue.ToString();
}
}