ICustomAttributeProvider.GetCustomAttributes 方法

定义

返回此成员上定义的自定义属性。Returns custom attributes defined on this member.

重载

GetCustomAttributes(Boolean)

返回在该成员上定义的所有自定义特性的数组(已命名的特性除外),如果没有自定义特性,则返回空数组。Returns an array of all of the custom attributes defined on this member, excluding named attributes, or an empty array if there are no custom attributes.

GetCustomAttributes(Type, Boolean)

返回在该成员上定义、由类型标识的自定义属性数组,如果没有该类型的自定义属性,则返回空数组。Returns an array of custom attributes defined on this member, identified by type, or an empty array if there are no custom attributes of that type.

GetCustomAttributes(Boolean)

返回在该成员上定义的所有自定义特性的数组(已命名的特性除外),如果没有自定义特性,则返回空数组。Returns an array of all of the custom attributes defined on this member, excluding named attributes, or an empty array if there are no custom attributes.

public:
 cli::array <System::Object ^> ^ GetCustomAttributes(bool inherit);
public object[] GetCustomAttributes (bool inherit);
abstract member GetCustomAttributes : bool -> obj[]
Public Function GetCustomAttributes (inherit As Boolean) As Object()

参数

inherit
Boolean

true 时,查找继承的自定义特性的层次结构链。When true, look up the hierarchy chain for the inherited custom attribute.

返回

Object[]

表示自定义特性的对象数组或空数组。An array of Objects representing custom attributes, or an empty array.

异常

无法加载自定义特性类型。The custom attribute type cannot be loaded.

此成员上定义了多个 attributeType 类型的特性。There is more than one attribute of type attributeType defined on this member.

注解

GetCustomAttributes trueinherit 参数时,对 PropertyInfoEventInfo 调用 ICustomAttributeProvider.GetCustomAttributes 不会遍历类型层次结构。Calling ICustomAttributeProvider.GetCustomAttributes on PropertyInfo or EventInfo when the inherit parameter of GetCustomAttributes is true does not walk the type hierarchy. 使用 System.Attribute 可继承自定义属性。Use System.Attribute to inherit custom attributes.

此方法只返回直接在非继承成员上定义的自定义属性。This method returns custom attributes defined directly on a non-inherited member only.

GetCustomAttributes(Type, Boolean)

返回在该成员上定义、由类型标识的自定义属性数组,如果没有该类型的自定义属性,则返回空数组。Returns an array of custom attributes defined on this member, identified by type, or an empty array if there are no custom attributes of that type.

public:
 cli::array <System::Object ^> ^ GetCustomAttributes(Type ^ attributeType, bool inherit);
public object[] GetCustomAttributes (Type attributeType, bool inherit);
abstract member GetCustomAttributes : Type * bool -> obj[]
Public Function GetCustomAttributes (attributeType As Type, inherit As Boolean) As Object()

参数

attributeType
Type

自定义属性的类型。The type of the custom attributes.

inherit
Boolean

true 时,查找继承的自定义特性的层次结构链。When true, look up the hierarchy chain for the inherited custom attribute.

返回

Object[]

表示自定义特性的对象数组或空数组。An array of Objects representing custom attributes, or an empty array.

异常

无法加载自定义特性类型。The custom attribute type cannot be loaded.

attributeTypenullattributeType is null.

注解

如果 attributeType 是基类或接口,则此方法返回该类型的任何实现。If attributeType is a base class or interface, this method returns any implementation of that type.

此方法只返回直接在非继承成员上定义的自定义属性。This method returns custom attributes defined directly on a non-inherited member only.

GetCustomAttributes trueinherit 参数时,对 PropertyInfoEventInfo 调用 ICustomAttributeProvider.GetCustomAttributes 不会遍历类型层次结构。Calling ICustomAttributeProvider.GetCustomAttributes on PropertyInfo or EventInfo when the inherit parameter of GetCustomAttributes is true does not walk the type hierarchy. 使用 System.Attribute 可继承自定义属性。Use System.Attribute to inherit custom attributes.

适用于