ConstructorArgumentAttribute Class

Definition

指定可以使用非无参数构造函数语法来初始化对象,而且由指定名称的属性提供构造信息。Specifies that an object can be initialized by using a non-parameterless constructor syntax, and that a property of the specified name supplies construction information. 此信息主要用于 XAML 序列化。This information is primarily for XAML serialization.

public ref class ConstructorArgumentAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public sealed class ConstructorArgumentAttribute : Attribute
type ConstructorArgumentAttribute = class
    inherit Attribute
Public NotInheritable Class ConstructorArgumentAttribute
Inherits Attribute
Inheritance
ConstructorArgumentAttribute
Attributes

Remarks

此特性指定关联的属性可由构造函数参数进行初始化,并且如果构造函数用于构造实例,则 XAML 序列化应忽略该属性。This attribute specifies that the associated property can be initialized by a constructor parameter and should be ignored for XAML serialization if the constructor is used to construct the instance. 这为参数化构造函数语法提供更好的往返表示形式,而不是无参数构造函数实例化和特定属性。This provides better round trip representations for parameterized constructor syntax rather than parameterless constructor instantiation plus specific attributes.

框架可能支持保留标记扩展用法并对其进行重组,而不是依赖于对象树中用于序列化的 ProvideValue 输出。A framework can potentially support preserving markup extension usages and reconstituting them rather than relying on ProvideValue output in the object tree for serialization. 在这种情况下,在序列化过程中,ConstructorArgumentAttribute 信息非常有用,用于生成典型标记扩展用法的准确表示形式。In this case, the ConstructorArgumentAttribute information is useful during serialization for producing an accurate representation of the typical markup extension usage. 有关标记扩展的详细信息,请参阅 Markup Extensions for XAML OverviewFor more information about markup extensions, see Markup Extensions for XAML Overview.

为了使 ConstructorArgumentAttribute 归属有效,类型的公共非参数构造函数必须仅支持一个参数。In order to be valid for a ConstructorArgumentAttribute attribution, a type's public non-parameterless constructor must support exactly one parameter. 参数的名称必须与读/写属性相对应。The name of the parameter must correspond to a read/write property. 该属性必须是可序列化的。The property must be otherwise serializable. 使用此属性可以在构造函数中的参数名称与属性之间创建对应关系。You use this attribute to create the correspondence between the name of the parameter in the constructor, and the property. 具体而言,将此特性应用于连接读/写属性的属性级定义。Specifically, you apply this attribute to the property-level definition of the connecting read/write property.

如果 ArgumentName 未解析为类型支持,或应用于没有合适的构造参数和 arity 的类型,ConstructorArgumentAttribute 的使用者可能会引发。Consumers of ConstructorArgumentAttribute may throw in cases where ArgumentName does not resolve to type backing, or when applied to a type that does not have the appropriate construction arguments and arity.

在 .NET Framework 的以前版本中,此类存在于 WPF 特定的程序集 WindowsBase 中。In previous versions of the .NET Framework, this class existed in the WPF-specific assembly WindowsBase. .NET Framework 4.NET Framework 4中,ConstructorArgumentAttribute 在 system.exception 程序集中。In .NET Framework 4.NET Framework 4, ConstructorArgumentAttribute is in the System.Xaml assembly. 有关详细信息,请参阅 Types Migrated from WPF to System.XamlFor more information, see Types Migrated from WPF to System.Xaml.

WPF 用法说明WPF Usage Notes

有关标记扩展和 WPF 的详细信息,请参阅标记扩展和 WPF XAMLFor more information about markup extensions and WPF, see Markup Extensions and WPF XAML.

Constructors

ConstructorArgumentAttribute(String)

初始化 ConstructorArgumentAttribute 类的新实例。Initializes a new instance of the ConstructorArgumentAttribute class.

Properties

ArgumentName

获取将初始化关联的属性的构造函数的 name 参数。Gets the name parameter of the constructor that will initialize the associated property.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Methods

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Applies to

See also