Assembly.GetCustomAttributes 方法

定義

取得這個組裝的自訂屬性。

多載

名稱 Description
GetCustomAttributes(Boolean)

取得這個元件的所有自定義屬性。

GetCustomAttributes(Type, Boolean)

取得這個元件的自定義屬性,如 型別所指定。

GetCustomAttributes(Boolean)

取得這個元件的所有自定義屬性。

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)

取得這個元件的自定義屬性,如 型別所指定。

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 沒有存取器或列舉器。

適用於