mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-04-24 13:57:11 -04:00
Add GetAttribute for enums
This commit is contained in:
parent
79361d92cb
commit
a4a50b880c
1 changed files with 17 additions and 0 deletions
17
src/NzbDrone.Common/Extensions/EnumExtensions.cs
Normal file
17
src/NzbDrone.Common/Extensions/EnumExtensions.cs
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue