2024-03-06 16:14:36 +01:00

25 lines
1003 B
C#

namespace DigitalData.Core.Attributes
{
/// <summary>
/// Provides helper methods for working with attributes.
/// </summary>
public static class AttrHelper
{
/// <summary>
/// Retrieves the <see cref="ADFilterAttribute"/> applied to a given type.
/// </summary>
/// <typeparam name="T">The type to examine for the attribute.</typeparam>
/// <returns>The <see cref="ADFilterAttribute"/> found on the type; null if the attribute is not present.</returns>
public static ADFilterAttribute? GetFilterAttrOf<T>()
{
// Get the ADFilterAttribute from the type, if it exists
Attribute? attr = Attribute.GetCustomAttribute(typeof(T), typeof(ADFilterAttribute));
// Check if the attribute is of the expected type and return it; otherwise, return null
if (attr is ADFilterAttribute fAttr)
return fAttr;
return null;
}
}
}