mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +00:00
31 lines
827 B
C#
31 lines
827 B
C#
using System.ComponentModel;
|
|
|
|
namespace FFMpegCore.Extensions.Downloader.Extensions;
|
|
|
|
public static class EnumExtensions
|
|
{
|
|
internal static string GetDescription(this Enum enumValue)
|
|
{
|
|
var field = enumValue.GetType().GetField(enumValue.ToString());
|
|
if (field == null)
|
|
{
|
|
return enumValue.ToString();
|
|
}
|
|
|
|
if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)
|
|
{
|
|
return attribute.Description;
|
|
}
|
|
|
|
return enumValue.ToString();
|
|
}
|
|
|
|
public static TEnum[] GetFlags<TEnum>(this TEnum input) where TEnum : Enum
|
|
{
|
|
return Enum.GetValues(input.GetType())
|
|
.Cast<Enum>()
|
|
.Where(input.HasFlag)
|
|
.Cast<TEnum>()
|
|
.ToArray();
|
|
}
|
|
}
|