initial commit
This commit is contained in:
25
DigitalData.Core.Attributes/AttributeHelper.cs
Normal file
25
DigitalData.Core.Attributes/AttributeHelper.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user