Assembly.GetCustomAttributes 方法

定义

获取此程序集的自定义属性。

重载

GetCustomAttributes(Boolean)

获取此程序集的所有自定义属性。

GetCustomAttributes(Type, Boolean)

获取按类型指定的此程序集的自定义属性。

GetCustomAttributes(Boolean)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

获取此程序集的所有自定义属性。

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

参数

inherit
Boolean

对于 Assembly 类型的对象,将忽略此参数。

返回

Object[]

包含此程序集自定义属性的数组。

实现

注解

此方法实现相应的 ICustomAttributeProvider 接口方法。 因此,即使忽略参数, inherit 也必须指定参数。

伪属性指示存在该特性时必须设置的核心元数据的位。 与扩展类型的元数据并随类型一起保存的自定义属性不同,伪属性修改类型的元数据,然后被丢弃。 某些生成的位无法使用现有反射 API 进行访问。

下表汇总了反射中可用的位的不同伪属性和访问器。

Pseudo-Attribute 元数据位 反射访问器
DllImportAttribute CorPInvokeMap

DLL 名称
对于普通方法/全局方法属性,没有 的 PInvokeMap 访问器。

DLL 名称没有访问器。
GuidAttribute 存储为真正的自定义属性。 作为真正的自定义属性访问。
ComImportAttribute CorTypeAttr.tdImport Type.Attributes.Import
SerializableAttribute CorTypeAttr.tdSerializable Type.Attributes.Serializable
NonSerializedAttribute CorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerialized
MethodImplAttribute CorMethodImpl MethodInfo.GetMethodImplementationFlags()

ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttribute 各种位。 无访问器。
PreserveSigAttribute CorMethodImpl.miOLE MethodInfo.GetMethodImplementationFlags().OLE

ConstructorInfo.GetMethodImplementationFlags().OLE
InAttribute CorParamAttr.pdIn ParameterInfo.Attributes.In
OutAttribute CorParamAttr.pdOut ParameterInfo.Attributes.Out
StructLayoutAttribute CorTypeAttr.tdLayoutSequential

CorTypeAttr.tdExplicitLayout

CorTypeAttr.tdAnsiClass

CorTypeAttr.tdUnicodeClass

CorTypeAttr.tdAutoClass

类打包。
Type.Attributes.LayoutSequential

Type.Attributes.ExplicitLayout

Type.Attributes.AnsiClass

Type.Attributes.UnicodeClass

Type.Attributes.AutoClass

无访问器。
FieldOffsetAttribute 字段偏移量。 无访问器。
AssemblyLoadAttribute CorAssemblyFlags 无访问器或枚举器。

适用于

GetCustomAttributes(Type, Boolean)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

获取按类型指定的此程序集的自定义属性。

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

参数

attributeType
Type

要为其返回自定义属性的类型。

inherit
Boolean

对于 Assembly 类型的对象,将忽略此参数。

返回

Object[]

一个数组,它包含由 attributeType 指定的此程序集的自定义属性。

实现

例外

attributeTypenull

attributeType 不是运行时类型。

注解

此方法实现相应的 ICustomAttributeProvider 接口方法。 因此,即使忽略参数, inherit 也必须指定参数。

伪属性指示存在该特性时必须设置的核心元数据的位。 与扩展类型的元数据并随类型一起保存的自定义属性不同,伪属性修改类型的元数据,然后被丢弃。 某些生成的位无法使用现有反射 API 进行访问。

下表汇总了反射中可用的位的不同伪属性和访问器。

Pseudo-Attribute 元数据位 反射访问器
DllImportAttribute CorPInvokeMap

DLL 名称
对于普通方法/全局方法属性,没有 的 PInvokeMap 访问器。

DLL 名称没有访问器。
GuidAttribute 存储为真正的自定义属性。 作为真正的自定义属性访问。
ComImportAttribute CorTypeAttr.tdImport Type.Attributes.Import
SerializableAttribute CorTypeAttr.tdSerializable Type.Attributes.Serializable
NonSerializedAttribute CorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerialized
MethodImplAttribute CorMethodImpl MethodInfo.GetMethodImplementationFlags()

ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttribute 各种位。 无访问器。
PreserveSigAttribute CorMethodImpl.miOLE MethodInfo.GetMethodImplementationFlags().OLE

ConstructorInfo.GetMethodImplementationFlags().OLE
InAttribute CorParamAttr.pdIn ParameterInfo.Attributes.In
OutAttribute CorParamAttr.pdOut ParameterInfo.Attributes.Out
StructLayoutAttribute CorTypeAttr.tdLayoutSequential

CorTypeAttr.tdExplicitLayout

CorTypeAttr.tdAnsiClass

CorTypeAttr.tdUnicodeClass

CorTypeAttr.tdAutoClass

类打包。
Type.Attributes.LayoutSequential

Type.Attributes.ExplicitLayout

Type.Attributes.AnsiClass

Type.Attributes.UnicodeClass

Type.Attributes.AutoClass

无访问器。
FieldOffsetAttribute 字段偏移量。 无访问器。
AssemblyLoadAttribute CorAssemblyFlags 无访问器或枚举器。

适用于