mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
feat: Re-adding missing util method for getting class attributes
This commit is contained in:
@@ -42,13 +42,42 @@ namespace ICD.Common.Utils
|
|||||||
if (type == null)
|
if (type == null)
|
||||||
throw new ArgumentNullException("type");
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
// ReSharper disable InvokeAsExtensionMethod
|
return GetClassAttributes<T>(type, inherit).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the attributes on the given class type matching the generic type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<T> GetClassAttributes<T>(Type type)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
|
return GetClassAttributes<T>(type, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the attributes on the given class type matching the generic type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="inherit"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<T> GetClassAttributes<T>(Type type, bool inherit)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
|
// ReSharper disable InvokeAsExtensionMethod
|
||||||
return ReflectionExtensions.GetCustomAttributes<T>(
|
return ReflectionExtensions.GetCustomAttributes<T>(
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
(CType)
|
(CType)
|
||||||
#endif
|
#endif
|
||||||
type, inherit).FirstOrDefault();
|
type, inherit);
|
||||||
// ReSharper restore InvokeAsExtensionMethod
|
// ReSharper restore InvokeAsExtensionMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user