feat: Re-adding missing util method for getting class attributes

This commit is contained in:
Chris Cameron
2019-08-01 09:24:17 -04:00
parent 6eda848410
commit 5700cf4ce2

View File

@@ -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>