XamlReader Class

Provides base definitions for classes that consume XAML input and produce XAML node streams.

Namespace:  System.Xaml
Assembly:  System.Xaml (in System.Xaml.dll)

public abstract class XamlReader : IDisposable

The XamlReader type exposes the following members.

  NameDescription
Protected methodXamlReaderInitializes the XamlReader class.
Top

  NameDescription
Protected propertyIsDisposedGets whether Dispose has been called.
Public propertyIsEofWhen implemented in a derived class, gets a value that reports whether the reader position is at end-of-file.
Public propertyMemberWhen implemented in a derived class, gets the current member at the reader position, if the reader position is on a StartMember.
Public propertyNamespaceWhen implemented in a derived class, gets the XAML namespace information from the current node.
Public propertyNodeTypeWhen implemented in a derived class, gets the type of the current node.
Public propertySchemaContextWhen implemented in a derived class, gets an object that provides XAML schema context information for the information set.
Public propertyTypeWhen implemented in a derived class, gets the XamlType of the current node.
Public propertyValueWhen implemented in a derived class, gets the value of the current node.
Top

  NameDescription
Public methodCloseCloses the XAML node stream.
Protected methodDisposeReleases the unmanaged resources used by the XamlReader, and optionally, releases the managed resources.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodReadWhen implemented in a derived class, provides the next XAML node from the source, if a node is available.
Public methodReadSubtreeReturns 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.
Public methodSkipSkips the current node and advances the reader position to the next node.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDisposable.DisposeInfrastructure. Releases all resources used by the current instance of the XamlReader class.
Top

XamlReader is an abstract class and does not provide implementations or definitions that have a working result for all members. Members that do have an implementation in XamlReader are noted in the remarks for that member. Specifically, XamlReader has several abstract members that must be implemented, and several virtual members.

Of the virtual members, ReadSubtree and Skip each provide a default implementation that is appropriate for most cases. 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 is also a virtual member that has a working default implementation.

The following two classes are the most relevant and practical derived classes in .NET Framework XAML Services and the System.Xaml assembly:

  • XamlObjectReader, which reads an object graph, such as the active object graph of an application at run time.

  • 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.

Other XAML readers from other frameworks include Baml2006Reader and XamlDebuggerXmlReader.

XamlReader differs from XML Document Object Model (DOM) and XmlReader design principles because XamlReader does not have a Create method to return underlying default XAML reader implementations. You must instead instantiate specific derived XAML reader classes by calling their constructors or other class-specific helper APIs.

Subtree Readers

For the most part, you call XamlReader API in the context of specific XAML reader classes that derive from XamlReader. However, 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. This case is when you call ReadSubtree, which returns a XamlReader instance. In the default implementation, the XamlReader that is returned by this API is an internal class.

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. The 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.

Notes about subtree reader usage are included on certain XamlReader APIs.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft