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-AttributePseudo-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 MethodInfo.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-AttributePseudo-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 MethodInfo.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

适用于