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
DllImportAttributeDllImportAttribute 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-Attribute 中繼資料位Metadata Bits 反映存取子Reflection Accessor
DllImportAttributeDllImportAttribute 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

適用於