diff --git a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs index f22b19b..79f344b 100644 --- a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs +++ b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs @@ -14,6 +14,21 @@ namespace ICD.Common.Utils.Extensions /// public static class ReflectionExtensions { + /// + /// Returns the custom attributes attached to the member. + /// + /// + /// + /// + public static IEnumerable GetCustomAttributes(this ICustomAttributeProvider extends) + where T : Attribute + { + if (extends == null) + throw new ArgumentNullException("extends"); + + return extends.GetCustomAttributes(false); + } + /// /// Returns the custom attributes attached to the member. /// @@ -29,5 +44,36 @@ namespace ICD.Common.Utils.Extensions return extends.GetCustomAttributes(typeof(T), inherits).Cast(); } + + /// + /// Returns the custom attribute attached to the member. + /// + /// + /// + /// + public static T GetCustomAttribute(this ICustomAttributeProvider extends) + where T : Attribute + { + if (extends == null) + throw new ArgumentNullException("extends"); + + return extends.GetCustomAttribute(false); + } + + /// + /// Returns the custom attribute attached to the member. + /// + /// + /// + /// + /// + public static T GetCustomAttribute(this ICustomAttributeProvider extends, bool inherits) + where T : Attribute + { + if (extends == null) + throw new ArgumentNullException("extends"); + + return extends.GetCustomAttributes(inherits).First(); + } } } diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index 82ab92c..0aaeab0 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using ICD.Common.Properties; +using ICD.Common.Utils.Extensions; using ICD.Common.Utils.IO; #if SIMPLSHARP using Crestron.SimplSharp.CrestronIO; @@ -251,9 +252,6 @@ namespace ICD.Common.Utils if (assembly == null) throw new ArgumentNullException("assembly"); -#if SIMPLSHARP - return assembly.GetCustomAttributes(typeof(T), false).Cast(); -#else try { return assembly.GetCustomAttributes(); @@ -262,7 +260,6 @@ namespace ICD.Common.Utils { return Enumerable.Empty(); } -#endif } ///