ConstructorArgumentAttribute 類別

定義

指定可使用非無參數建構函式語法而初始化的物件,以及所指定名稱的屬性會提供建構資訊。 這項資訊主要供 XAML 序列化之用。

public ref class ConstructorArgumentAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public sealed class ConstructorArgumentAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)>]
type ConstructorArgumentAttribute = class
    inherit Attribute
Public NotInheritable Class ConstructorArgumentAttribute
Inherits Attribute
繼承
ConstructorArgumentAttribute
屬性

備註

這個屬性會指定建構函式參數可以初始化相關聯的屬性,如果使用建構函式來建構實例,則應該忽略 XAML 串行化。 這可提供參數化建構函式語法的較佳來回表示法,而不是無參數建構函式具現化加上特定屬性。

架構可能支援保留標記延伸用法,並加以重新建構,而不是依賴 ProvideValue 物件樹狀結構中的輸出進行串行化。 在此情況下, ConstructorArgumentAttribute 資訊在串行化期間很有用,以產生一般標記延伸使用方式的精確表示法。 如需標記延伸的詳細資訊,請參閱 Markup Extensions for XAML Overview

若要對 ConstructorArgumentAttribute 屬性有效,類型的公用非無參數建構函式必須只支援一個參數。 參數的名稱必須對應至讀取/寫入屬性。 屬性必須可串行化。 您可以使用這個屬性來建立建構函式中參數名稱與 屬性之間的對應。 具體而言,您會將這個屬性套用至連接讀取/寫入屬性的屬性層級定義。

的取用者 ConstructorArgumentAttribute 可能會在無法解析為型別支持的情況下 ArgumentName 擲回,或套用至沒有適當建構自變數和arity的類型時。

在舊版的 .NET Framework 中,這個類別存在於 WPF 特定的元件 WindowsBase 中。 在 .NET Framework 4 中,ConstructorArgumentAttribute位於 System.Xaml 元件中。 如需詳細資訊,請參閱 Types Migrated from WPF to System.Xaml

WPF 使用注意事項

如需標記延伸和 WPF 的詳細資訊,請參閱 標記延伸和 WPF XAML

建構函式

ConstructorArgumentAttribute(String)

初始化 ConstructorArgumentAttribute 類別的新執行個體。

屬性

ArgumentName

取得將初始化相關聯屬性的建構函式名稱參數。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱