| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- using System.Collections.Generic;
- namespace System.Reflection
- {
- public static class CustomAttributeExtensions
- {
- #region APIs that return a single attribute
- public static Attribute? GetCustomAttribute(this Assembly element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static Attribute? GetCustomAttribute(this Module element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static Attribute? GetCustomAttribute(this MemberInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static Attribute? GetCustomAttribute(this ParameterInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static T? GetCustomAttribute<T>(this Assembly element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static T? GetCustomAttribute<T>(this Module element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static T? GetCustomAttribute<T>(this MemberInfo element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static T? GetCustomAttribute<T>(this ParameterInfo element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static Attribute? GetCustomAttribute(this MemberInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttribute(element, attributeType, inherit);
- }
- public static Attribute? GetCustomAttribute(this ParameterInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttribute(element, attributeType, inherit);
- }
- public static T? GetCustomAttribute<T>(this MemberInfo element, bool inherit) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T), inherit);
- }
- public static T? GetCustomAttribute<T>(this ParameterInfo element, bool inherit) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T), inherit);
- }
- #endregion
- #region APIs that return all attributes
- public static IEnumerable<Attribute> GetCustomAttributes(this Assembly element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this Module element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, inherit);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, inherit);
- }
- #endregion
- #region APIs that return all attributes of a particular type
- public static IEnumerable<Attribute> GetCustomAttributes(this Assembly element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this Module element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this Assembly element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this Module element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this ParameterInfo element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, attributeType, inherit);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, attributeType, inherit);
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element, bool inherit) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T), inherit);
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this ParameterInfo element, bool inherit) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T), inherit);
- }
- #endregion
- #region IsDefined
- public static bool IsDefined(this Assembly element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this Module element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this MemberInfo element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this ParameterInfo element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this MemberInfo element, Type attributeType, bool inherit)
- {
- return Attribute.IsDefined(element, attributeType, inherit);
- }
- public static bool IsDefined(this ParameterInfo element, Type attributeType, bool inherit)
- {
- return Attribute.IsDefined(element, attributeType, inherit);
- }
- #endregion
- }
- }
|