Assembly.GetCustomAttributes Assembly.GetCustomAttributes Assembly.GetCustomAttributes Assembly.GetCustomAttributes Method

定义

获取此程序集的自定义属性。Gets the custom attributes for this assembly.

重载

GetCustomAttributes(Boolean) GetCustomAttributes(Boolean) GetCustomAttributes(Boolean) GetCustomAttributes(Boolean)

获取此程序集的所有自定义属性。Gets all the custom attributes for this assembly.

GetCustomAttributes(Type, Boolean) GetCustomAttributes(Type, Boolean) GetCustomAttributes(Type, Boolean) GetCustomAttributes(Type, Boolean)

获取按类型指定的此程序集的自定义属性。Gets the custom attributes for this assembly as specified by type.

GetCustomAttributes(Boolean) GetCustomAttributes(Boolean) GetCustomAttributes(Boolean) GetCustomAttributes(Boolean)

获取此程序集的所有自定义属性。Gets all the custom attributes for this assembly.

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

对于 Assembly 类型的对象,将忽略此参数。This argument is ignored for objects of type Assembly.

返回

Object[]

包含此程序集自定义属性的数组。An array that contains the custom attributes for this assembly.

实现

注解

此方法实现相应ICustomAttributeProvider的接口方法。This method implements the corresponding ICustomAttributeProvider interface method. 因此, 必须inherit指定参数, 即使该参数被忽略。Therefore, the inherit parameter must be specified even though it is ignored.

伪属性指示在属性存在时必须设置的核心元数据的位数。A pseudo-attribute indicates bits of the core metadata that must be set when the attribute is present. 与扩展类型的元数据的自定义特性不同, 与类型一起保存时, 伪特性会修改类型的元数据, 然后被丢弃。Unlike a custom attribute that extends the metadata for a type and is saved along with the type, a pseudo-attribute modifies the metadata for the type and then is discarded. 某些生成的位无法使用现有的反射 Api 进行访问。Some of the resulting bits cannot be accessed using existing reflection APIs.

下表总结了反射中可用的位的不同伪属性和访问器。The following table summarizes the different pseudo-attributes and the accessors for the bits that are available in reflection.

伪特性Pseudo-Attribute 元数据位Metadata Bits 反射访问器Reflection Accessor
SubDllImportAttribute CorPInvokeMapCorPInvokeMap

DLL 名称DLL name
对于普通方法/全局方法特性, 没有适用于 PInvokeMap 的访问器。No accessor for PInvokeMap for ordinary method/global method attributes.

没有 DLL 名称的访问器。No accessor for DLL name.
GuidAttributeGuidAttribute 存储为实际的自定义属性。Stored as a real custom attribute. 作为真实的自定义属性进行访问。Accessed as a real custom attribute.
ComImportAttributeComImportAttribute CorTypeAttr.tdImportCorTypeAttr.tdImport Type.Attributes.ImportType.Attributes.Import
SerializableAttributeSerializableAttribute CorTypeAttr.tdSerializableCorTypeAttr.tdSerializable Type.Attributes.SerializableType.Attributes.Serializable
NonSerializedAttributeNonSerializedAttribute CorFieldAttr.fdNotSerializedCorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerializedFieldInfo.Attributes.NotSerialized
MethodImplAttributeMethodImplAttribute CorMethodImplCorMethodImpl MethodInfo.GetMethodImplementationFlags()MethodInfo.GetMethodImplementationFlags()

ConstructorInfo. GetMethodImplementationFlags ()ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttributeMarshalAsAttribute 各种位。Various bits. 无访问器。No accessor.
PreserveSigAttributePreserveSigAttribute CorMethodImpl.miOLECorMethodImpl.miOLE GetMethodImplementationFlags ()。OLEMethodInfo.GetMethodImplementationFlags().OLE

ConstructorInfo. GetMethodImplementationFlags ()。OLEConstructorInfo.GetMethodImplementationFlags().OLE
InAttributeInAttribute CorParamAttr.pdInCorParamAttr.pdIn ParameterInfo.Attributes.InParameterInfo.Attributes.In
OutAttributeOutAttribute CorParamAttr.pdOutCorParamAttr.pdOut ParameterInfo.Attributes.OutParameterInfo.Attributes.Out
StructLayoutAttributeStructLayoutAttribute CorTypeAttr.tdLayoutSequentialCorTypeAttr.tdLayoutSequential

CorTypeAttr.tdExplicitLayoutCorTypeAttr.tdExplicitLayout

CorTypeAttr.tdAnsiClassCorTypeAttr.tdAnsiClass

CorTypeAttr.tdUnicodeClassCorTypeAttr.tdUnicodeClass

CorTypeAttr.tdAutoClassCorTypeAttr.tdAutoClass

类打包。Class packing.
Type.Attributes.LayoutSequentialType.Attributes.LayoutSequential

Type.Attributes.ExplicitLayoutType.Attributes.ExplicitLayout

Type.Attributes.AnsiClassType.Attributes.AnsiClass

Type.Attributes.UnicodeClassType.Attributes.UnicodeClass

Type.Attributes.AutoClassType.Attributes.AutoClass

无访问器。No accessor.
FieldOffsetAttributeFieldOffsetAttribute 字段偏移量。Field offset. 无访问器。No accessor.
AssemblyLoadAttributeAssemblyLoadAttribute CorAssemblyFlagsCorAssemblyFlags 无取值函数或枚举器。No accessor or enumerator.

安全性

ReflectionPermission
当通过诸如InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])等机制后期绑定调用时。when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). 关联的枚举:MemberAccessAssociated enumeration: MemberAccess

GetCustomAttributes(Type, Boolean) GetCustomAttributes(Type, Boolean) GetCustomAttributes(Type, Boolean) GetCustomAttributes(Type, Boolean)

获取按类型指定的此程序集的自定义属性。Gets the custom attributes for this assembly as specified by type.

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

要为其返回自定义属性的类型。The type for which the custom attributes are to be returned.

inherit
Boolean Boolean Boolean Boolean

对于 Assembly 类型的对象,将忽略此参数。This argument is ignored for objects of type Assembly.

返回

Object[]

一个数组,它包含由 attributeType 指定的此程序集的自定义属性。An array that contains the custom attributes for this assembly as specified by attributeType.

实现

异常

attributeType 不是运行时类型。attributeType is not a runtime type.

注解

此方法实现相应ICustomAttributeProvider的接口方法。This method implements the corresponding ICustomAttributeProvider interface method. 因此, 必须inherit指定参数, 即使该参数被忽略。Therefore, the inherit parameter must be specified even though it is ignored.

伪属性指示在属性存在时必须设置的核心元数据的位数。A pseudo-attribute indicates bits of the core metadata that must be set when the attribute is present. 与扩展类型的元数据的自定义特性不同, 与类型一起保存时, 伪特性会修改类型的元数据, 然后被丢弃。Unlike a custom attribute that extends the metadata for a type and is saved along with the type, a pseudo-attribute modifies the metadata for the type and then is discarded. 某些生成的位无法使用现有的反射 Api 进行访问。Some of the resulting bits cannot be accessed using existing reflection APIs.

下表总结了反射中可用的位的不同伪属性和访问器。The following table summarizes the different pseudo-attributes and the accessors for the bits that are available in reflection.

伪特性Pseudo-Attribute 元数据位Metadata Bits 反射访问器Reflection Accessor
SubDllImportAttribute CorPInvokeMapCorPInvokeMap

DLL 名称DLL name
对于普通方法/全局方法特性, 没有适用于 PInvokeMap 的访问器。No accessor for PInvokeMap for ordinary method/global method attributes.

没有 DLL 名称的访问器。No accessor for DLL name.
GuidAttributeGuidAttribute 存储为实际的自定义属性。Stored as a real custom attribute. 作为真实的自定义属性进行访问。Accessed as a real custom attribute.
ComImportAttributeComImportAttribute CorTypeAttr.tdImportCorTypeAttr.tdImport Type.Attributes.ImportType.Attributes.Import
SerializableAttributeSerializableAttribute CorTypeAttr.tdSerializableCorTypeAttr.tdSerializable Type.Attributes.SerializableType.Attributes.Serializable
NonSerializedAttributeNonSerializedAttribute CorFieldAttr.fdNotSerializedCorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerializedFieldInfo.Attributes.NotSerialized
MethodImplAttributeMethodImplAttribute CorMethodImplCorMethodImpl MethodInfo.GetMethodImplementationFlags()MethodInfo.GetMethodImplementationFlags()

ConstructorInfo. GetMethodImplementationFlags ()ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttributeMarshalAsAttribute 各种位。Various bits. 无访问器。No accessor.
PreserveSigAttributePreserveSigAttribute CorMethodImpl.miOLECorMethodImpl.miOLE GetMethodImplementationFlags ()。OLEMethodInfo.GetMethodImplementationFlags().OLE

ConstructorInfo. GetMethodImplementationFlags ()。OLEConstructorInfo.GetMethodImplementationFlags().OLE
InAttributeInAttribute CorParamAttr.pdInCorParamAttr.pdIn ParameterInfo.Attributes.InParameterInfo.Attributes.In
OutAttributeOutAttribute CorParamAttr.pdOutCorParamAttr.pdOut ParameterInfo.Attributes.OutParameterInfo.Attributes.Out
StructLayoutAttributeStructLayoutAttribute CorTypeAttr.tdLayoutSequentialCorTypeAttr.tdLayoutSequential

CorTypeAttr.tdExplicitLayoutCorTypeAttr.tdExplicitLayout

CorTypeAttr.tdAnsiClassCorTypeAttr.tdAnsiClass

CorTypeAttr.tdUnicodeClassCorTypeAttr.tdUnicodeClass

CorTypeAttr.tdAutoClassCorTypeAttr.tdAutoClass

类打包。Class packing.
Type.Attributes.LayoutSequentialType.Attributes.LayoutSequential

Type.Attributes.ExplicitLayoutType.Attributes.ExplicitLayout

Type.Attributes.AnsiClassType.Attributes.AnsiClass

Type.Attributes.UnicodeClassType.Attributes.UnicodeClass

Type.Attributes.AutoClassType.Attributes.AutoClass

无访问器。No accessor.
FieldOffsetAttributeFieldOffsetAttribute 字段偏移量。Field offset. 无访问器。No accessor.
AssemblyLoadAttributeAssemblyLoadAttribute CorAssemblyFlagsCorAssemblyFlags 无取值函数或枚举器。No accessor or enumerator.

安全性

ReflectionPermission
当通过诸如InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])等机制后期绑定调用时。when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). 关联的枚举:MemberAccessAssociated enumeration: MemberAccess

适用于