mirror of
https://github.com/ckaczor/ChrisKaczor.MinifluxClient.git
synced 2026-02-16 18:46:52 -05:00
Initial commit
This commit is contained in:
27
Library/EnumExtensions.cs
Normal file
27
Library/EnumExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace ChrisKaczor.MinifluxClient;
|
||||
|
||||
internal static class EnumExtensions
|
||||
{
|
||||
internal static TAttribute? GetAttribute<TAttribute>(this Enum enumValue) where TAttribute : Attribute
|
||||
{
|
||||
var type = enumValue.GetType();
|
||||
|
||||
var name = Enum.GetName(type, enumValue);
|
||||
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
var field = type.GetField(name);
|
||||
|
||||
var attribute = field?.GetCustomAttribute<TAttribute>();
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
extension<T>(T value) where T : Enum
|
||||
{
|
||||
internal string QueryPropertyName => value.GetAttribute<QueryParameterNameAttribute>()?.Name ?? string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user