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)

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

指示一个指定类型的自定义特性是否应用于一个指定的数字,并选择性地应用于其的上级。

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

参数

element
MemberInfo

要检查的成员。

attributeType
Type

要搜索的特性类型。

inherit
Boolean

如果检查 element 的上级,则为 true;否则为 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)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
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)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
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)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
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)

Source:
CustomAttributeExtensions.cs
Source:
CustomAttributeExtensions.cs
Source:
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)

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

指示一个指定类型的自定义特性是否应用于一个指定的参数,并选择性地应用于其的上级。

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

参数

element
ParameterInfo

要检查的参数。

attributeType
Type

要搜索的属性的类型。

inherit
Boolean

如果检查 element 的上级,则为 true;否则为 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