CustomAttributeExtensions.IsDefined 方法

定義

指出是否將自訂屬性套用至項目。

多載

IsDefined(MemberInfo, Type, Boolean)

指出指定之型別的自訂屬性是否會套用至指定的成員,以及選擇性地套用到其上階。

IsDefined(Assembly, Type)

指出是否將所指定型別的自訂屬性套用至指定的組件。

IsDefined(MemberInfo, Type)

指出是否將所指定型別的自訂屬性套用至指定的成員。

IsDefined(Module, Type)

指出是否將所指定型別的自訂屬性套用至指定的模組。

IsDefined(ParameterInfo, Type)

指出是否將所指定型別的自訂屬性套用至指定的參數。

IsDefined(ParameterInfo, Type, Boolean)

指出指定之型別的自訂屬性是否會套用至指定的參數,以及選擇性地套用到其上階。

IsDefined(MemberInfo, Type, Boolean)

來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs

指出指定之型別的自訂屬性是否會套用至指定的成員,以及選擇性地套用到其上階。

C#
public static bool IsDefined (this System.Reflection.MemberInfo element, Type attributeType, bool inherit);

參數

element
MemberInfo

要檢查的成員。

attributeType
Type

要搜尋之屬性的型別。

inherit
Boolean

true 表示檢查element的祖系,否則為false

傳回

如果指定的型別的屬性套用至 element,則為 true,否則為 false

例外狀況

elementattributeTypenull

attributeType 不是衍生自 Attribute

element 不是建構函式、方法、屬性、事件、型別或欄位。

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsDefined(Assembly, Type)

來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs

指出是否將所指定型別的自訂屬性套用至指定的組件。

C#
public static bool IsDefined (this System.Reflection.Assembly element, Type attributeType);

參數

element
Assembly

要檢查的組件。

attributeType
Type

要搜尋之屬性的型別。

傳回

如果指定的型別的屬性套用至 element,則為 true,否則為 false

例外狀況

elementattributeTypenull

attributeType 不是衍生自 Attribute

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsDefined(MemberInfo, Type)

來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs

指出是否將所指定型別的自訂屬性套用至指定的成員。

C#
public static bool IsDefined (this System.Reflection.MemberInfo element, Type attributeType);

參數

element
MemberInfo

要檢查的成員。

attributeType
Type

要搜尋的屬性類型。

傳回

如果指定的型別的屬性套用至 element,則為 true,否則為 false

例外狀況

elementattributeTypenull

attributeType 不是衍生自 Attribute

element 不是建構函式、方法、屬性、事件、型別或欄位。

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsDefined(Module, Type)

來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs

指出是否將所指定型別的自訂屬性套用至指定的模組。

C#
public static bool IsDefined (this System.Reflection.Module element, Type attributeType);

參數

element
Module

要檢查的模型。

attributeType
Type

要搜尋的屬性類型。

傳回

如果指定的型別的屬性套用至 element,則為 true,否則為 false

例外狀況

elementattributeTypenull

attributeType 不是衍生自 Attribute

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsDefined(ParameterInfo, Type)

來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs

指出是否將所指定型別的自訂屬性套用至指定的參數。

C#
public static bool IsDefined (this System.Reflection.ParameterInfo element, Type attributeType);

參數

element
ParameterInfo

要檢查的參數。

attributeType
Type

要搜尋的屬性類型。

傳回

如果指定的型別的屬性套用至 element,則為 true,否則為 false

例外狀況

elementattributeTypenull

attributeType 不是衍生自 Attribute

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsDefined(ParameterInfo, Type, Boolean)

來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs
來源:
CustomAttributeExtensions.cs

指出指定之型別的自訂屬性是否會套用至指定的參數,以及選擇性地套用到其上階。

C#
public static bool IsDefined (this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);

參數

element
ParameterInfo

要檢查的參數。

attributeType
Type

要搜尋的屬性類型。

inherit
Boolean

true 表示檢查element的祖系,否則為false

傳回

如果指定的型別的屬性套用至 element,則為 true,否則為 false

例外狀況

elementattributeTypenull

attributeType 不是衍生自 Attribute

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0