Add GetAttribute for enums

pull/1791/head
Bogdan 11 months ago
parent 79361d92cb
commit a4a50b880c

@ -0,0 +1,17 @@
using System;
using System.Linq;
namespace NzbDrone.Common.Extensions
{
public static class EnumExtensions
{
public static T GetAttribute<T>(this Enum value)
where T : Attribute
{
var enumType = value.GetType();
var name = Enum.GetName(enumType, value);
return name == null ? null : enumType.GetField(name)?.GetCustomAttributes(false).OfType<T>().SingleOrDefault();
}
}
}
Loading…
Cancel
Save