From f7b5ef49c86de0d2f79c9c85efc92d8c6ba6926f Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 26 Apr 2022 10:32:02 +0100 Subject: [PATCH] Remove Type.HasCustomAttribute and Type.SelectFromCustomAttribute Since Type inherits MemberInfo, these methods are implicitly available via MemberInfoExtensions --- .../ReflectionExtensions/TypeExtensions.cs | 86 ------------------- 1 file changed, 86 deletions(-) diff --git a/X10D/src/ReflectionExtensions/TypeExtensions.cs b/X10D/src/ReflectionExtensions/TypeExtensions.cs index 03e13ba..8a8d4d5 100644 --- a/X10D/src/ReflectionExtensions/TypeExtensions.cs +++ b/X10D/src/ReflectionExtensions/TypeExtensions.cs @@ -8,59 +8,6 @@ namespace X10D; /// public static class TypeExtensions { - /// - /// Returns a value indicating whether or not the current type has been decorated with a specified attribute. - /// - /// The type whose attributes to check. - /// The attribute type. - /// - /// if the current type has been decorated with a specified attribute, or - /// otherwise. - /// - /// is . - public static bool HasCustomAttribute(this Type type) - where T : Attribute - { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - return type.HasCustomAttribute(typeof(T)); - } - - /// - /// Returns a value indicating whether or not the current type has been decorated with a specified attribute. - /// - /// The type whose attributes to check. - /// The attribute type. - /// - /// if the current type has been decorated with a specified attribute, or - /// otherwise. - /// - /// is . - public static bool HasCustomAttribute(this Type type, Type attribute) - { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - if (attribute is null) - { - throw new ArgumentNullException(nameof(attribute)); - } - - if (!attribute.Inherits()) - { - throw new ArgumentException( - string.Format(CultureInfo.CurrentCulture, ExceptionMessages.TypeDoesNotInheritAttribute, attribute), - nameof(attribute)); - } - - return type.GetCustomAttribute(attribute) is not null; - } - /// /// Returns a value indicating whether the current type implements a specified interface. /// @@ -155,37 +102,4 @@ public static class TypeExtensions return value.IsSubclassOf(type); } - - /// - /// Retrieves a custom attribute that is decorated by the current type, and projects it into to a new form. - /// - /// The attribute type. - /// The return type of the delegate. - /// The type. - /// A transform function to apply to the attribute. - /// - /// An instance of as provided from . - /// - /// - /// is - /// -or- - /// is . - /// - public static TReturn? SelectFromCustomAttribute(this Type type, Func selector) - where TAttribute : Attribute - { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } - - if (selector is null) - { - throw new ArgumentNullException(nameof(selector)); - } - - return type.GetCustomAttribute() is { } attribute - ? selector(attribute) - : default; - } }