Assembly.GetCustomAttributes 方法

定義

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

多載

GetCustomAttributes(Boolean)

取得這個組件的所有自訂屬性。

GetCustomAttributes(Type, Boolean)

取得這個組件由類型所指定的自訂屬性。

GetCustomAttributes(Boolean)

來源:
Assembly.cs
來源:
Assembly.cs
來源:
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)

來源:
Assembly.cs
來源:
Assembly.cs
來源:
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 沒有存取子或列舉值。

適用於