XamlObjectWriter 类

定义

从源 XAML 节点流创建对象图。Creates an object graph from a source XAML node stream.

public ref class XamlObjectWriter : System::Xaml::XamlWriter, System::Xaml::IXamlLineInfoConsumer
public class XamlObjectWriter : System.Xaml.XamlWriter, System.Xaml.IXamlLineInfoConsumer
type XamlObjectWriter = class
    inherit XamlWriter
    interface IXamlLineInfoConsumer
Public Class XamlObjectWriter
Inherits XamlWriter
Implements IXamlLineInfoConsumer
继承
XamlObjectWriter
实现

注解

XamlObjectWriterWrite 方法实现模式,以便 XamlObjectWriter 使用由 WriteNode 方法定义的 XamlWriterThe Write methods of XamlObjectWriter implement a pattern so that the XamlObjectWriter uses the XamlWriter that is defined by the WriteNode method. WriteNode 逻辑在 Write 方法之间切换,具体取决于读取器中当前位置的节点类型。WriteNode logic switches between the Write methods, depending on which node type is at the current position in the reader.

范围Scope

XamlObjectWriter 具有范围的概念;也就是说,XamlObjectWriter 在其输出对象关系图中维护一个概念点引用。A XamlObjectWriter has a concept of scope; that is, the XamlObjectWriter maintains a conceptual point of reference in its output object graph. 对于特定范围,某些操作可能有效或无效,或者产生无操作结果。For a particular scope, certain operations might be valid or invalid, or produce a no-operation result. 例如,如果调用 WriteStartMember 来写入已作为实例存在的对象上的初始化指令,则默认实现将引发异常。For example, if you call WriteStartMember to write directives for initialization on an object that already exists as an instance, the default implementation throws an exception.

跟踪自定义 XamlObjectWriter 中的作用域的可能方法是将节点操作与堆栈或帧类对齐。A possible technique for tracking scope in a custom XamlObjectWriter is to align the node actions with a stack or frame class. XamlObjectWriter 写入对象图时,堆栈或帧可以跟踪输入或退出的对象模型深度的每个级别的 push 和 pop。The stack or frame can keep track of push and pop for each level of object-model depth that is entered or exited while the XamlObjectWriter writes the object graph.

回调Callbacks

为了支持中级和高级 XamlObjectWriter 方案,编写对象图的机制提供了 XamlObjectWriter 提交或将要提交特定操作时出现的回调入口点。To support intermediate and advanced XamlObjectWriter scenarios, the mechanism of writing an object graph provides callback entry points that occur when a XamlObjectWriter commits or is about to commit certain actions. 某些回调在设置中启用,并且不特定于对象类型或被写入的成员;但是,回调信息通常在上下文中提供,或在通过回调发送的事件数据中提供。Some callbacks are enabled in the settings and are not specific to the object type or the member being written; however, callback information is often available in context or is in the event data that is sent through the callback. 下面是相关回调的列表:The following is a list of relevant callbacks:

写入字典键Writing Dictionary Keys

XamlObjectWriter 的默认实现支持在将字典内容添加到对象图之前 Dictionary<TKey,TValue> 的约束的类型转换。The default implementation of XamlObjectWriter supports type conversion on the constraints of a Dictionary<TKey,TValue> before the dictionary contents are added to the object graph. 通过这种方式,一般字典可在运行时按对象进行键控,并可与相关的泛型 Add 和索引器行为匹配。In this manner, a generic dictionary can be keyed at run time by objects and can match the relevant generic Add and indexer behavior. 但是,在为基 XamlObjectWriter实现时,此功能仅适用于从基本 Dictionary<TKey,TValue> 类创建的对象图,不适用于 Dictionary<TKey,TValue>的派生类。However, as implemented for the base XamlObjectWriter, this capability exists only for object graph creation from the base Dictionary<TKey,TValue> class and not for derived classes of Dictionary<TKey,TValue>.

检查是否已释放Checks for Disposed

XAML 编写器可能用于延迟的操作,或对已在中期中释放的 XAML 编写器实例进行调用的位置。XAML writers are potentially used for deferred operations or where a call is made against a XAML writer instance that has been disposed in the interim. 在这些情况下,XamlObjectWriter 的各种 Api 可能引发 ObjectDisposedExceptionVarious APIs of XamlObjectWriter might throw ObjectDisposedException in these cases.

构造函数

XamlObjectWriter(XamlSchemaContext)

使用 XamlObjectWriter 所用的 XAML 架构上下文初始化 XamlReader 类的新实例。Initializes a new instance of the XamlObjectWriter class using the XAML schema context that is used by a XamlReader.

XamlObjectWriter(XamlSchemaContext, XamlObjectWriterSettings)

使用 XamlObjectWriter 所用的上下文及其设置初始化 XamlReader 类的新实例。Initializes a new instance of the XamlObjectWriter class using the context that is used by a XamlReader and its settings.

属性

IsDisposed

获取的值指示是否已调用了 Dispose(Boolean)Gets whether Dispose(Boolean) has been called.

(继承自 XamlWriter)
Result

获取写入的最后一个对象。Gets the last object that was written. 通常,仅在节点流位于结尾且对象关系图完整时才调用。Typically only called when the node stream is at its end and the object graph is complete.

RootNameScope

获取 INameScope 服务,该服务为 XAML 对象编写器的绝对根节点维护 XAML 名称范围。Gets the INameScope service that maintains the XAML namescope for the absolute node root of the XAML object writer.

SchemaContext

获取活动 XAML 架构上下文。Gets the active XAML schema context.

ShouldProvideLineInfo

获取一个值,该值报告行信息服务是否应提供值并因此在相关时同时调用 SetLineInfo(Int32, Int32) 方法。Gets a value that reports whether a line information service should provide values and therefore, should also call the SetLineInfo(Int32, Int32) method when it is relevant.

方法

Clear()

重置所有可能的框架并清除对象图。Resets all possible frames and clears the object graph.

Close()

关闭 XAML 编写器对象。Closes the XAML writer object.

(继承自 XamlWriter)
Dispose(Boolean)

释放由 XamlObjectWriter 占用的非托管资源,也可以选择释放托管资源。Releases the unmanaged resources used by the XamlObjectWriter, and optionally, releases the managed resources.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
OnAfterBeginInit(Object)

为此 AfterBeginInitHandler 调用任何与 XamlObjectWriterSettings 关联的 XamlObjectWriter 方法。Invokes any AfterBeginInitHandler method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

OnAfterEndInit(Object)

为此 AfterEndInitHandler 调用任何与 XamlObjectWriterSettings 关联的 XamlObjectWriter 方法。Invokes any AfterEndInitHandler method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

OnAfterProperties(Object)

为此 AfterPropertiesHandler 调用任何与 XamlObjectWriterSettings 关联的 XamlObjectWriter 引用的方法。Invokes any AfterPropertiesHandler referenced method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

OnBeforeProperties(Object)

为此 BeforePropertiesHandler 调用任何与 XamlObjectWriterSettings 关联的 XamlObjectWriter 引用的方法。Invokes any BeforePropertiesHandler referenced method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

OnSetValue(Object, XamlMember, Object)

为此编写器调用任何与 XamlSetValueHandler 关联的 XamlObjectWriterSettings 引用的方法(只要 handled 事件数据中的 XamlSetValueEventArgs 不为 true)。Invokes any XamlSetValueHandler referenced method that is associated with XamlObjectWriterSettings for this writer, as long as handled in XamlSetValueEventArgs event data is not true.

SetLineInfo(Int32, Int32)

实现 SetLineInfo(Int32, Int32),并为异常提供行信息。Implements SetLineInfo(Int32, Int32) and provides line information for exceptions.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
WriteEndMember()

关闭当前成员范围,并且可能在关闭时写入成员范围的值。Closes the current member scope, and may write the value of the member scope while it closes. 新范围将成为成员的父对象范围。The new scope becomes the parent object scope of the member.

WriteEndObject()

关闭编写器中的当前对象范围。Closes the current object scope in the writer. 新对象范围将成为的父成员范围。The new object scope becomes the parent member scope.

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.

WriteNamespace(NamespaceDeclaration)

定义一个命名空间声明,该声明适用于下一个对象范围或成员范围。Defines a namespace declaration that applies to the next object scope or member scope.

WriteNode(XamlReader)

基于 XAML 读取器中的节点类型 (NodeType) 执行切换,并为编写器实现调用相关的 Write 方法。Performs switching based on node type from the XAML reader (NodeType) and calls the relevant Write method for the writer implementation.

(继承自 XamlWriter)
WriteStartMember(XamlMember)

将新成员节点写入当前对象范围,并且该范围将成为新的成员范围。Writes a new member node into the current object scope, and the scope becomes a new member scope.

WriteStartObject(XamlType)

将对象节点写入当前范围,并将该范围设置为新对象范围。Writes an object node into the current scope, and sets the scope to a new object scope.

WriteValue(Object)

将值写入当前成员范围。Writes a value to the current member scope. 如果当前范围位于集合、字典或数组对象内部,则应将该值添加到集合、字典或数组中。If the current scope is inside a collection, dictionary, or array object, the value should be added to the collection, dictionary, or array.

显式接口实现

IDisposable.Dispose()

请参阅 Dispose()See Dispose().

(继承自 XamlWriter)

适用于

另请参阅