XamlReader 类

定义

为使用 XAML 输入并生成 XAML 节点流的类提供基定义。Provides base definitions for classes that consume XAML input and produce XAML node streams.

public ref class XamlReader abstract : IDisposable
public abstract class XamlReader : IDisposable
type XamlReader = class
    interface IDisposable
Public MustInherit Class XamlReader
Implements IDisposable
继承
XamlReader
派生
实现

注解

XamlReader 是一个抽象类,不提供具有所有成员的工作结果的实现或定义。XamlReader is an abstract class and does not provide implementations or definitions that have a working result for all members. XamlReader 中具有实现的成员在该成员的备注中注明。Members that do have an implementation in XamlReader are noted in the remarks for that member. 具体而言,XamlReader 具有多个必须实现的抽象成员和多个虚拟成员。Specifically, XamlReader has several abstract members that must be implemented, and several virtual members.

ReadSubtreeSkip 每个虚拟成员均提供适用于大多数情况的默认实现。Of the virtual members, ReadSubtree and Skip each provide a default implementation that is appropriate for most cases. ReadSubtreeSkip 默认实现依赖于实现 XAML 读取器的其他预期行为;具体而言,它们依赖于 Read 重写。However, the ReadSubtree and Skip default implementations rely on other expected behavior of the implementing XAML reader; in particular, they rely on the Read override. Dispose 也是具有工作默认实现的虚拟成员。Dispose is also a virtual member that has a working default implementation.

以下两个类是 .NET Framework XAML 服务和 system.exception 程序集中最相关和实用的派生类:The following two classes are the most relevant and practical derived classes in .NET Framework XAML Services and the System.Xaml assembly:

  • XamlObjectReader,它在运行时读取对象图,如应用程序的活动对象图。XamlObjectReader, which reads an object graph, such as the active object graph of an application at run time.

  • XamlXmlReader,它使用将文件作为中间帮助器类加载的常规 XmlReader,以 XML 文本文件的形式读取 XAML。XamlXmlReader, which reads XAML in the form of a XML text file by using a general XmlReader that loads the file as an intermediary helper class.

其他框架中的其他 XAML 读取器包括 Baml2006ReaderXamlDebuggerXmlReaderOther XAML readers from other frameworks include Baml2006Reader and XamlDebuggerXmlReader.

XamlReader 不同于 XML 文档对象模型 (DOM)XML Document Object Model (DOM)XmlReader 设计原则,因为 XamlReader 没有 Create 方法返回基础默认 XAML 读取器实现。XamlReader differs from XML 文档对象模型 (DOM)XML Document Object Model (DOM) and XmlReader design principles because XamlReader does not have a Create method to return underlying default XAML reader implementations. 您必须通过调用其构造函数或其他特定于类的帮助程序 Api 来实例化特定的派生 XAML 读取器类。You must instead instantiate specific derived XAML reader classes by calling their constructors or other class-specific helper APIs.

子树读取器Subtree Readers

大多数情况下,在从 XamlReader派生的特定 XAML 读取器类的上下文中调用 XamlReader API。For the most part, you call XamlReader API in the context of specific XAML reader classes that derive from XamlReader. 但是,在某个特定情况下,你可以访问非公共 XAML 读取器实例上的 XamlReader API,而不是派生自 XamlObjectReaderXamlXmlReaderHowever, in one particular case, you access XamlReader API on a practical XAML reader instance that is not public and not derived from XamlObjectReader or XamlXmlReader. 在这种情况下,您调用 ReadSubtree,这将返回一个 XamlReader 实例。This case is when you call ReadSubtree, which returns a XamlReader instance. 在默认实现中,此 API 返回的 XamlReader 是内部类。In the default implementation, the XamlReader that is returned by this API is an internal class.

为子树读取获取的 XamlReader 具有 ReadNodeType等 Api 的有效操作,这些操作基于父读取器类。The XamlReader obtained for subtree reading has valid actions for APIs such as Read and NodeType, and those actions are based on the parent reader class. 此设计允许内部类跟踪子树的输入位置的框架级别。This design enables the internal class to track the frame level where the subtree was entered. 操作子树 XamlReader 确保当当前节点位置超出子树的边界时,特定子树读取器会报告当前节点上的文件尾或 nullThe acting subtree XamlReader makes sure that if the current node position is moved beyond the bounds of the subtree, the specific subtree reader reports end-of-file or null at the current node.

某些 XamlReader Api 上包含有关子树读取器使用情况的说明。Notes about subtree reader usage are included on certain XamlReader APIs.

构造函数

XamlReader()

初始化 XamlReader 类。Initializes the XamlReader class.

属性

IsDisposed

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

IsEof

在派生类中实现时,获取一个值,该值报告读取器位置是否位于文件结尾。When implemented in a derived class, gets a value that reports whether the reader position is at end-of-file.

Member

在派生类中实现时,如果读取器位置在 StartMember 上,则获取位于读取器位置处的当前成员。When implemented in a derived class, gets the current member at the reader position, if the reader position is on a StartMember.

Namespace

在派生类中实现时,从当前节点中获取 XAML 命名空间信息。When implemented in a derived class, gets the XAML namespace information from the current node.

NodeType

在派生类中实现时,获取当前节点的类型。When implemented in a derived class, gets the type of the current node.

SchemaContext

在派生类中实现时,获取一个对象,该对象提供信息集的 XAML 架构上下文信息。When implemented in a derived class, gets an object that provides XAML schema context information for the information set.

Type

在派生类中实现时,获取当前节点的 XamlTypeWhen implemented in a derived class, gets the XamlType of the current node.

Value

在派生类中实现时,获取当前节点的值。When implemented in a derived class, gets the value of the current node.

方法

Close()

关闭 XAML 节点流。Closes the XAML node stream.

Dispose(Boolean)

释放由 XamlReader 占用的非托管资源,也可以选择释放托管资源。Releases the unmanaged resources used by the XamlReader, 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)
Read()

在派生类中实现时,提供源中的下一个 XAML 节点(如果节点可用)。When implemented in a derived class, provides the next XAML node from the source, if a node is available.

ReadSubtree()

返回基于当前 XamlReaderXamlReader,其中返回的 XamlReader 用于循环访问 XAML 节点结构。Returns a XamlReader that is based on the current XamlReader, where the returned XamlReader is used to iterate through a subtree of the XAML node structure.

Skip()

跳过当前节点并将读取器位置推进到下一个节点。Skips the current node and advances the reader position to the next node.

ToString()

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

(继承自 Object)

显式接口实现

IDisposable.Dispose()

释放由 XamlReader 类的当前实例占用的所有资源。Releases all resources used by the current instance of the XamlReader class.

适用于

另请参阅