CustomAttributeExtensions.GetCustomAttribute 方法

定義

擷取套用到指定元素的自訂屬性。

多載

名稱 Description
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)

擷取套用至指定元件之指定型別的自定義屬性。

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);
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 如果找不到這樣的屬性。

例外狀況

elementattributeTypenull

attributeType 並非由 推導而來 Attribute

找到了多個要求的屬性。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute(MemberInfo, Type)

擷取指定型別的自訂屬性,套用到指定成員。

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);
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 如果找不到這樣的屬性。

例外狀況

elementattributeTypenull

attributeType 並非由 推導而來 Attribute

element 不是建構子、方法、屬性、事件、類型或欄位。

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute(Module, Type)

擷取指定型別的自訂屬性,套用到指定模組。

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);
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 如果找不到這樣的屬性。

例外狀況

elementattributeTypenull

attributeType 並非由 推導而來 Attribute

找到了多個要求的屬性。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute(ParameterInfo, Type)

擷取指定型態的自訂屬性,套用到指定參數。

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);
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 如果找不到這樣的屬性。

例外狀況

elementattributeTypenull

attributeType 並非由 推導而來 Attribute

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute(MemberInfo, Type, Boolean)

擷取指定類型的自訂屬性,套用於指定成員,並可選擇性地檢查該成員的祖先。

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);
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

true以檢視祖element先;否則,。 false

傳回

一個符合 attributeType的自訂屬性,或者 null 如果找不到這樣的屬性。

例外狀況

elementattributeTypenull

attributeType 並非由 推導而來 Attribute

element 不是建構子、方法、屬性、事件、類型或欄位。

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute(ParameterInfo, Type, Boolean)

擷取指定類型的自訂屬性,套用於指定參數,並可選擇性檢查該參數的祖先。

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);
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

true以檢視祖element先;否則,。 false

傳回

自訂屬性匹配 attributeType,或 null 若找不到此類屬性。

例外狀況

elementattributeTypenull

attributeType 並非由 推導而來 Attribute

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute<T>(ParameterInfo, Boolean)

擷取指定類型的自訂屬性,套用於指定參數,並可選擇性檢查該參數的祖先。

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;
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

true以檢視祖element先;否則,。 false

傳回

T

一個符合 T的自訂屬性,或者 null 如果找不到這樣的屬性。

例外狀況

elementnull

element 不是建構子、方法、屬性、事件、類型或欄位。

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute<T>(MemberInfo, Boolean)

擷取指定類型的自訂屬性,套用於指定成員,並可選擇性地檢查該成員的祖先。

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;
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

true以檢視祖element先;否則,。 false

傳回

T

一個符合 T的自訂屬性,或者 null 如果找不到這樣的屬性。

例外狀況

elementnull

element 不是建構子、方法、屬性、事件、類型或欄位。

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute<T>(ParameterInfo)

擷取指定型態的自訂屬性,套用到指定參數。

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;
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 如果找不到這樣的屬性。

例外狀況

elementnull

element 不是建構子、方法、屬性、事件、類型或欄位。

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute<T>(Module)

擷取指定型別的自訂屬性,套用到指定模組。

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;
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 如果找不到這樣的屬性。

例外狀況

elementnull

找到了多個要求的屬性。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute<T>(MemberInfo)

擷取指定型別的自訂屬性,套用到指定成員。

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;
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 如果找不到這樣的屬性。

例外狀況

elementnull

element 不是建構子、方法、屬性、事件、類型或欄位。

找到了多個要求的屬性。

自訂屬性型別無法載入。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於

GetCustomAttribute<T>(Assembly)

擷取套用至指定元件之指定型別的自定義屬性。

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;
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 如果找不到這樣的屬性。

例外狀況

elementnull

找到了多個要求的屬性。

備註

如果你預期會回傳多個值或AmbiguousMatchException會拋出,就使用 GetCustomAttributes extension 方法。

適用於