XamlObjectWriter.WriteGetObject 方法

定义

当指定对象是父属性的默认值或隐式值时,将概念 StartObject 写入对象关系图。Writes the conceptual StartObject into the object graph when the specified object is a default or implicit value of the parent property. 隐式值来自从 XAML 架构上下文中获取的信息以及后备类型信息,而不是指定为输入 XAML 节点集中的对象值。The implicit value comes from information that is obtained from the XAML schema context and backing type information, instead of being specified as an object value in the input XAML node set.

public:
 override void WriteGetObject();
public override void WriteGetObject ();
override this.WriteGetObject : unit -> unit
Public Overrides Sub WriteGetObject ()

注解

在生成的对象图中,可以在生成的对象图中查看通过 WriteGetObject 编写和用 WriteStartObject 进行写入的区别。The difference between writing with WriteGetObject and writing with WriteStartObject can be seen in the resulting object graph. WriteGetObject 不构造类型的实例,因为 WriteGetObject API 没有任何信息来通知对象关系图的构造。WriteGetObject does not construct an instance of a type because the WriteGetObject API has no information to inform the object graph of what to construct. 相反,对象是在初始化父属性时创建的;因此,XamlObjectWriter 不需要构造它。Instead, the object was created when the parent property was initialized; so a XamlObjectWriter does not need to construct it. 相反,WriteStartObject 指定应构造该类型的实例并将其插入到对象图中。In contrast, WriteStartObject specifies that an instance of that type should be constructed and inserted into the object graph.

如果将 XAML 节点流视为一系列帧,则 WriteGetObject 会平衡到 WriteEndObject 调用。If you think of the XAML node stream as a series of frames, a WriteGetObject is balanced to a WriteEndObject call. 因此,WriteGetObjectWriteStartObject 调用的数量应该等于 WriteEndObject 调用数,作为 XAML 节点流的完整对象写入计算的一部分。Therefore, the number of WriteGetObject plus WriteStartObject calls should equal the number of WriteEndObject calls as part of a complete object-writing evaluation of the XAML node stream.

对象图中的隐式对象的概念 StartObject 位置是必需的,因为虽然对象值本身是隐式默认值,但该对象可能仍有需要基于 XAML 节点流编写的成员。The conceptual StartObject position for an implicit object in the object graph is necessary because although the object value itself is an implicit default, that object might still have members that need to be written based on the XAML node stream. 出现这种情况的典型情况是 XamlObjectWriter 为集合属性写入成员节点,并且集合初始化是隐式的,以创建拥有集合属性的对象。A typical scenario where this occurs is when XamlObjectWriter writes member nodes for a collection property, and the collection initialization is implicit to creating the object that owns the collection property.

适用于