This commit is contained in:
TheXamlGuy
2024-05-31 14:07:35 +01:00
parent 041dd81717
commit 8f1a3252c6
10 changed files with 112 additions and 41 deletions
+13 -1
View File
@@ -22,11 +22,23 @@ public static class ObjectExtensions
where TAttribute : Attribute
{
Type type = obj.GetType();
if (type.GetAttribute<TAttribute>() is TAttribute attribute)
if (type.GetCustomAttribute<TAttribute>(true) is TAttribute attribute)
{
return attribute;
}
return null;
}
public static IEnumerable<TAttribute> GetAttributes<TAttribute>(this object obj)
where TAttribute : Attribute
{
Type type = obj.GetType();
if (type.GetCustomAttributes<TAttribute>(true) is IEnumerable<TAttribute> attributes)
{
return attributes;
}
return Enumerable.Empty<TAttribute>();
}
}