From 5700cf4ce2bda799ad9258f7f30e452ec8d758a0 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 1 Aug 2019 09:24:17 -0400 Subject: [PATCH] feat: Re-adding missing util method for getting class attributes --- ICD.Common.Utils/AttributeUtils.cs | 37 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/ICD.Common.Utils/AttributeUtils.cs b/ICD.Common.Utils/AttributeUtils.cs index cfefd03..cd83d90 100644 --- a/ICD.Common.Utils/AttributeUtils.cs +++ b/ICD.Common.Utils/AttributeUtils.cs @@ -42,13 +42,42 @@ namespace ICD.Common.Utils if (type == null) throw new ArgumentNullException("type"); -// ReSharper disable InvokeAsExtensionMethod + return GetClassAttributes(type, inherit).FirstOrDefault(); + } + + /// + /// Gets the attributes on the given class type matching the generic type. + /// + /// + /// + /// + public static IEnumerable GetClassAttributes(Type type) + { + if (type == null) + throw new ArgumentNullException("type"); + + return GetClassAttributes(type, false); + } + + /// + /// Gets the attributes on the given class type matching the generic type. + /// + /// + /// + /// + /// + public static IEnumerable GetClassAttributes(Type type, bool inherit) + { + if (type == null) + throw new ArgumentNullException("type"); + + // ReSharper disable InvokeAsExtensionMethod return ReflectionExtensions.GetCustomAttributes( #if SIMPLSHARP - (CType) + (CType) #endif - type, inherit).FirstOrDefault(); -// ReSharper restore InvokeAsExtensionMethod + type, inherit); + // ReSharper restore InvokeAsExtensionMethod } ///