diff --git a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs index 7986791..a1ccc8a 100644 --- a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs +++ b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using ICD.Common.Properties; #if SIMPLSHARP using Crestron.SimplSharp.Reflection; #else @@ -83,5 +84,48 @@ namespace ICD.Common.Utils.Extensions return extends.GetCustomAttributes(inherits).First(); } + +#if NETSTANDARD + /// + /// Returns the custom attributes attached to the member. + /// + /// + /// + /// + /// + public static IEnumerable GetCustomAttributesIncludingBaseInterfaces(this Type extends) + where T : Attribute + { + return extends.GetCustomAttributes(true) + .Union(extends.GetInterfaces() + .SelectMany(interfaceType => interfaceType + .GetCustomAttributes(true))) + .Distinct(); + } + + /// + /// Returns the custom attributes attached to the member. + /// + /// + /// + /// + /// + public static IEnumerable GetCustomAttributesIncludingBaseInterfaces(this MemberInfo extends) + where T : Attribute + { + return extends.GetCustomAttributes(true) + .Union(extends.DeclaringType? + .GetInterfaces() + .SelectMany(interfaceType => interfaceType + .GetMember( + extends.Name, + extends.MemberType, + BindingFlags.Instance) + .FirstOrDefault()? + .GetCustomAttributes(true) ?? Enumerable.Empty())? + .Except(null) ?? Enumerable.Empty()) + .Distinct(); + } +#endif } }