语言

CustomAttributeExtensions.GetCustomAttribute 方法

定义

检索应用于指定元素的自定义属性。

重载

名称 说明
GetCustomAttribute(Assembly, Type)

检索应用于指定程序集的指定类型的自定义属性。

GetCustomAttribute(MemberInfo, Type)

检索应用于指定成员的指定类型的自定义属性。

GetCustomAttribute(Module, Type)

检索应用于指定模块的指定类型的自定义属性。

GetCustomAttribute(ParameterInfo, Type)

检索应用于指定参数的指定类型的自定义属性。

GetCustomAttribute(MemberInfo, Type, Boolean)

检索应用于指定成员的指定类型的自定义属性,并选择性地检查该成员的上级。

GetCustomAttribute(ParameterInfo, Type, Boolean)

检索应用于指定参数的指定类型的自定义属性,并选择性地检查该参数的上级。

GetCustomAttribute<T>(ParameterInfo, Boolean)

检索应用于指定参数的指定类型的自定义属性,并选择性地检查该参数的上级。

GetCustomAttribute<T>(MemberInfo, Boolean)

检索应用于指定成员的指定类型的自定义属性,并选择性地检查该成员的上级。

GetCustomAttribute<T>(ParameterInfo)

检索应用于指定参数的指定类型的自定义属性。

GetCustomAttribute<T>(Module)

检索应用于指定模块的指定类型的自定义属性。

GetCustomAttribute<T>(MemberInfo)

检索应用于指定成员的指定类型的自定义属性。

GetCustomAttribute<T>(Assembly)

检索应用于指定程序集的指定类型的自定义属性。

GetCustomAttribute(Assembly, Type)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定程序集的指定类型的自定义属性。

public:
[System::Runtime::CompilerServices::Extension]
 static Attribute ^ GetCustomAttribute(System::Reflection::Assembly ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute(this System.Reflection.Assembly element, Type attributeType);
public static Attribute? GetCustomAttribute(this System.Reflection.Assembly element, Type attributeType);
static member GetCustomAttribute : System.Reflection.Assembly * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As Assembly, attributeType As Type) As Attribute

参数

element
Assembly

要检查的程序集。

attributeType
Type

要搜索的属性的类型。

返回

匹配 attributeType的自定义属性,或者 null 找不到此类属性。

例外

element 或 attributeType 为 null.

attributeType 不是派生自 Attribute.

发现了多个请求的属性。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute(MemberInfo, Type)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定成员的指定类型的自定义属性。

public:
[System::Runtime::CompilerServices::Extension]
 static Attribute ^ GetCustomAttribute(System::Reflection::MemberInfo ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute(this System.Reflection.MemberInfo element, Type attributeType);
public static Attribute? GetCustomAttribute(this System.Reflection.MemberInfo element, Type attributeType);
static member GetCustomAttribute : System.Reflection.MemberInfo * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As MemberInfo, attributeType As Type) As Attribute

参数

element
MemberInfo

要检查的成员。

attributeType
Type

要搜索的属性的类型。

返回

匹配 attributeType的自定义属性,或者 null 找不到此类属性。

例外

element 或 attributeType 为 null.

attributeType 不是派生自 Attribute.

element 不是构造函数、方法、属性、事件、类型或字段。

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute(Module, Type)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定模块的指定类型的自定义属性。

public:
[System::Runtime::CompilerServices::Extension]
 static Attribute ^ GetCustomAttribute(System::Reflection::Module ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute(this System.Reflection.Module element, Type attributeType);
public static Attribute? GetCustomAttribute(this System.Reflection.Module element, Type attributeType);
static member GetCustomAttribute : System.Reflection.Module * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As Module, attributeType As Type) As Attribute

参数

element
Module

要检查的模块。

attributeType
Type

要搜索的属性的类型。

返回

匹配 attributeType的自定义属性,或者 null 找不到此类属性。

例外

element 或 attributeType 为 null.

attributeType 不是派生自 Attribute.

发现了多个请求的属性。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute(ParameterInfo, Type)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定参数的指定类型的自定义属性。

public:
[System::Runtime::CompilerServices::Extension]
 static Attribute ^ GetCustomAttribute(System::Reflection::ParameterInfo ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute(this System.Reflection.ParameterInfo element, Type attributeType);
public static Attribute? GetCustomAttribute(this System.Reflection.ParameterInfo element, Type attributeType);
static member GetCustomAttribute : System.Reflection.ParameterInfo * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As ParameterInfo, attributeType As Type) As Attribute

参数

element
ParameterInfo

要检查的参数。

attributeType
Type

要搜索的属性的类型。

返回

匹配 attributeType的自定义属性,或者 null 找不到此类属性。

例外

element 或 attributeType 为 null.

attributeType 不是派生自 Attribute.

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute(MemberInfo, Type, Boolean)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定成员的指定类型的自定义属性,并选择性地检查该成员的上级。

public:
[System::Runtime::CompilerServices::Extension]
 static Attribute ^ GetCustomAttribute(System::Reflection::MemberInfo ^ element, Type ^ attributeType, bool inherit);
public static Attribute GetCustomAttribute(this System.Reflection.MemberInfo element, Type attributeType, bool inherit);
public static Attribute? GetCustomAttribute(this System.Reflection.MemberInfo element, Type attributeType, bool inherit);
static member GetCustomAttribute : System.Reflection.MemberInfo * Type * bool -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As MemberInfo, attributeType As Type, inherit As Boolean) As Attribute

参数

element
MemberInfo

要检查的成员。

attributeType
Type

要搜索的属性的类型。

inherit
Boolean

(如果为 上级,则为 。

返回

匹配 attributeType的自定义属性,或者 null 找不到此类属性。

例外

element 或 attributeType 为 null.

attributeType 不是派生自 Attribute.

element 不是构造函数、方法、属性、事件、类型或字段。

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute(ParameterInfo, Type, Boolean)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定参数的指定类型的自定义属性,并选择性地检查该参数的上级。

public:
[System::Runtime::CompilerServices::Extension]
 static Attribute ^ GetCustomAttribute(System::Reflection::ParameterInfo ^ element, Type ^ attributeType, bool inherit);
public static Attribute GetCustomAttribute(this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);
public static Attribute? GetCustomAttribute(this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);
static member GetCustomAttribute : System.Reflection.ParameterInfo * Type * bool -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As ParameterInfo, attributeType As Type, inherit As Boolean) As Attribute

参数

element
ParameterInfo

要检查的参数。

attributeType
Type

要搜索的属性的类型。

inherit
Boolean

(如果为 上级,则为 。

返回

自定义属性匹配 attributeType,或者 null 找不到此类属性。

例外

element 或 attributeType 为 null.

attributeType 不是派生自 Attribute.

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute<T>(ParameterInfo, Boolean)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定参数的指定类型的自定义属性,并选择性地检查该参数的上级。

public:
generic <typename T>
 where T : Attribute[System::Runtime::CompilerServices::Extension]
 static T GetCustomAttribute(System::Reflection::ParameterInfo ^ element, bool inherit);
public static T GetCustomAttribute<T>(this System.Reflection.ParameterInfo element, bool inherit) where T : Attribute;
public static T? GetCustomAttribute<T>(this System.Reflection.ParameterInfo element, bool inherit) where T : Attribute;
static member GetCustomAttribute : System.Reflection.ParameterInfo * bool -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As ParameterInfo, inherit As Boolean) As T

类型参数

T

要搜索的属性的类型。

参数

element
ParameterInfo

要检查的参数。

inherit
Boolean

(如果为 上级,则为 。

返回

T

匹配 T的自定义属性,或者 null 找不到此类属性。

例外

element 是 null。

element 不是构造函数、方法、属性、事件、类型或字段。

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute<T>(MemberInfo, Boolean)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定成员的指定类型的自定义属性,并选择性地检查该成员的上级。

public:
generic <typename T>
 where T : Attribute[System::Runtime::CompilerServices::Extension]
 static T GetCustomAttribute(System::Reflection::MemberInfo ^ element, bool inherit);
public static T GetCustomAttribute<T>(this System.Reflection.MemberInfo element, bool inherit) where T : Attribute;
public static T? GetCustomAttribute<T>(this System.Reflection.MemberInfo element, bool inherit) where T : Attribute;
static member GetCustomAttribute : System.Reflection.MemberInfo * bool -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As MemberInfo, inherit As Boolean) As T

类型参数

T

要搜索的属性的类型。

参数

element
MemberInfo

要检查的成员。

inherit
Boolean

(如果为 上级,则为 。

返回

T

匹配 T的自定义属性,或者 null 找不到此类属性。

例外

element 是 null。

element 不是构造函数、方法、属性、事件、类型或字段。

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute<T>(ParameterInfo)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定参数的指定类型的自定义属性。

public:
generic <typename T>
 where T : Attribute[System::Runtime::CompilerServices::Extension]
 static T GetCustomAttribute(System::Reflection::ParameterInfo ^ element);
public static T GetCustomAttribute<T>(this System.Reflection.ParameterInfo element) where T : Attribute;
public static T? GetCustomAttribute<T>(this System.Reflection.ParameterInfo element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.ParameterInfo -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As ParameterInfo) As T

类型参数

T

要搜索的属性的类型。

参数

element
ParameterInfo

要检查的参数。

返回

T

匹配 T的自定义属性,或者 null 找不到此类属性。

例外

element 是 null。

element 不是构造函数、方法、属性、事件、类型或字段。

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute<T>(Module)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定模块的指定类型的自定义属性。

public:
generic <typename T>
 where T : Attribute[System::Runtime::CompilerServices::Extension]
 static T GetCustomAttribute(System::Reflection::Module ^ element);
public static T GetCustomAttribute<T>(this System.Reflection.Module element) where T : Attribute;
public static T? GetCustomAttribute<T>(this System.Reflection.Module element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.Module -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As Module) As T

类型参数

T

要搜索的属性的类型。

参数

element
Module

要检查的模块。

返回

T

匹配 T的自定义属性,或者 null 找不到此类属性。

例外

element 是 null。

发现了多个请求的属性。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute<T>(MemberInfo)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定成员的指定类型的自定义属性。

public:
generic <typename T>
 where T : Attribute[System::Runtime::CompilerServices::Extension]
 static T GetCustomAttribute(System::Reflection::MemberInfo ^ element);
public static T GetCustomAttribute<T>(this System.Reflection.MemberInfo element) where T : Attribute;
public static T? GetCustomAttribute<T>(this System.Reflection.MemberInfo element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.MemberInfo -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As MemberInfo) As T

类型参数

T

要搜索的属性的类型。

参数

element
MemberInfo

要检查的成员。

返回

T

匹配 T的自定义属性,或者 null 找不到此类属性。

例外

element 是 null。

element 不是构造函数、方法、属性、事件、类型或字段。

发现了多个请求的属性。

无法加载自定义属性类型。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于

GetCustomAttribute<T>(Assembly)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs

检索应用于指定程序集的指定类型的自定义属性。

public:
generic <typename T>
 where T : Attribute[System::Runtime::CompilerServices::Extension]
 static T GetCustomAttribute(System::Reflection::Assembly ^ element);
public static T GetCustomAttribute<T>(this System.Reflection.Assembly element) where T : Attribute;
public static T? GetCustomAttribute<T>(this System.Reflection.Assembly element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.Assembly -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As Assembly) As T

类型参数

T

要搜索的属性的类型。

参数

element
Assembly

要检查的程序集。

返回

T

匹配 T的自定义属性,或者 null 找不到此类属性。

例外

element 是 null。

发现了多个请求的属性。

注解

GetCustomAttributes如果希望返回多个值或AmbiguousMatchException将引发扩展方法,请使用扩展方法。

适用于