mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
feat: Re-adding missing util method for getting class attributes
This commit is contained in:
@@ -38,6 +38,35 @@ namespace ICD.Common.Utils
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
public static T GetClassAttribute<T>(Type type, bool inherit)
|
public static T GetClassAttribute<T>(Type type, bool inherit)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
|
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)
|
if (type == null)
|
||||||
throw new ArgumentNullException("type");
|
throw new ArgumentNullException("type");
|
||||||
@@ -47,7 +76,7 @@ namespace ICD.Common.Utils
|
|||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
(CType)
|
(CType)
|
||||||
#endif
|
#endif
|
||||||
type, inherit).FirstOrDefault();
|
type, inherit);
|
||||||
// ReSharper restore InvokeAsExtensionMethod
|
// ReSharper restore InvokeAsExtensionMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user