Assembly.GetCustomAttributes 方法

定義

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

多載

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 即使忽略參數,還是必須指定參數。

虛擬屬性指出當屬性存在時必須設定的核心中繼資料位。 不同于擴充型別中繼資料的自訂屬性,而且會隨著型別一起儲存,虛擬屬性(attribute)會修改類型的中繼資料,然後將它捨棄。 某些所產生的位無法使用現有的反映 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 即使忽略參數,還是必須指定參數。

虛擬屬性指出當屬性存在時必須設定的核心中繼資料位。 不同于擴充型別中繼資料的自訂屬性,而且會隨著型別一起儲存,虛擬屬性(attribute)會修改類型的中繼資料,然後將它捨棄。 某些所產生的位無法使用現有的反映 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 沒有存取子或列舉值。

適用於