XamlObjectWriter Class

.NET Framework (current version)
 

Creates an object graph from a source XAML node stream.

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

System.Object
  System.Xaml.XamlWriter
    System.Xaml.XamlObjectWriter

public class XamlObjectWriter : XamlWriter, IXamlLineInfoConsumer

NameDescription
System_CAPS_pubmethodXamlObjectWriter(XamlSchemaContext)

Initializes a new instance of the XamlObjectWriter class using the XAML schema context that is used by a XamlReader.

System_CAPS_pubmethodXamlObjectWriter(XamlSchemaContext, XamlObjectWriterSettings)

Initializes a new instance of the XamlObjectWriter class using the context that is used by a XamlReader and its settings.

NameDescription
System_CAPS_protpropertyIsDisposed

Gets whether Dispose has been called.(Inherited from XamlWriter.)

System_CAPS_pubpropertyResult

Gets the last object that was written. Typically only called when the node stream is at its end and the object graph is complete.

System_CAPS_pubpropertyRootNameScope

Gets the INameScope service that maintains the XAML namescope for the absolute node root of the XAML object writer.

System_CAPS_pubpropertySchemaContext

Gets the active XAML schema context.(Overrides XamlWriter.SchemaContext.)

System_CAPS_pubpropertyShouldProvideLineInfo

Gets a value that reports whether a line information service should provide values and therefore, should also call the SetLineInfo method when it is relevant.

NameDescription
System_CAPS_pubmethodClear()

Resets all possible frames and clears the object graph.

System_CAPS_pubmethodClose()

Closes the XAML writer object.(Inherited from XamlWriter.)

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the XamlObjectWriter, and optionally, releases the managed resources. (Overrides XamlWriter.Dispose(Boolean).)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnAfterBeginInit(Object)

Invokes any AfterBeginInitHandler method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

System_CAPS_protmethodOnAfterEndInit(Object)

Invokes any AfterEndInitHandler method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

System_CAPS_protmethodOnAfterProperties(Object)

Invokes any AfterPropertiesHandler referenced method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

System_CAPS_protmethodOnBeforeProperties(Object)

Invokes any BeforePropertiesHandler referenced method that is associated with XamlObjectWriterSettings for this XamlObjectWriter.

System_CAPS_protmethodOnSetValue(Object, XamlMember, Object)

Invokes any XamlSetValueHandler referenced method that is associated with XamlObjectWriterSettings for this writer, as long as handled in XamlSetValueEventArgs event data is not true.

System_CAPS_pubmethodSetLineInfo(Int32, Int32)

Implements IXamlLineInfoConsumer.SetLineInfo and provides line information for exceptions.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodWriteEndMember()

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.(Overrides XamlWriter.WriteEndMember().)

System_CAPS_pubmethodWriteEndObject()

Closes the current object scope in the writer. The new object scope becomes the parent member scope.(Overrides XamlWriter.WriteEndObject().)

System_CAPS_pubmethodWriteGetObject()

Writes the conceptual StartObject into the object graph when the specified object is a default or implicit value of the parent property. 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.(Overrides XamlWriter.WriteGetObject().)

System_CAPS_pubmethodWriteNamespace(NamespaceDeclaration)

Defines a namespace declaration that applies to the next object scope or member scope.(Overrides XamlWriter.WriteNamespace(NamespaceDeclaration).)

System_CAPS_pubmethodWriteNode(XamlReader)

Performs switching based on node type from the XAML reader (XamlReader.NodeType) and calls the relevant Write method for the writer implementation.(Inherited from XamlWriter.)

System_CAPS_pubmethodWriteStartMember(XamlMember)

Writes a new member node into the current object scope, and the scope becomes a new member scope.(Overrides XamlWriter.WriteStartMember(XamlMember).)

System_CAPS_pubmethodWriteStartObject(XamlType)

Writes an object node into the current scope, and sets the scope to a new object scope.(Overrides XamlWriter.WriteStartObject(XamlType).)

System_CAPS_pubmethodWriteValue(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.(Overrides XamlWriter.WriteValue(Object).)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIDisposable.Dispose()

This API supports the product infrastructure and is not intended to be used directly from your code. See Dispose.(Inherited from XamlWriter.)

The Write methods of XamlObjectWriter implement a pattern so that the XamlObjectWriter uses the XamlWriter that is defined by the WriteNode method. WriteNode logic switches between the Write methods, depending on which node type is at the current position in the reader.

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

A possible technique for tracking scope in a custom XamlObjectWriter is to align the node actions with a stack or frame class. 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.

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:

  • The callback that is declared by AfterBeginInitHandler is invoked when the scope goes to a new object and at the BeginInit phase of object lifetime for each created object.

  • The callback that is declared by AfterEndInitHandler is invoked when the scope goes to a new object and at the EndInit phase of object lifetime for each created object.

  • The callback that is declared by BeforePropertiesHandler is invoked when the scope starts in an object, and occurs when the first WriteStartMember call to that object scope is made but not yet committed.

  • The callback that is declared by AfterPropertiesHandler is invoked when the scope starts in an object, and happens when the WriteEndObject call to that object scope is made but not yet committed.

  • The callback that is declared by XamlSetValueHandler is invoked when OnSetValue is called.

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. In this manner, a generic dictionary can be keyed at run time by objects and can match the relevant generic Add and indexer behavior. 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>.

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. Various APIs of XamlObjectWriter might throw ObjectDisposedException in these cases.

.NET Framework
Available since 4.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: