SnapshotNode Class
Definition
Base class for all snapshot nodes. Contains no UI references. All data is owned by the snapshot and safe to access from any thread.
public class SnapshotNode
Remarks
SnapshotNode is designed for serialization scenarios (RTF/HTML export, autosave). It captures a point-in-time view of the document structure.
Memory per node varies by subtype:
- Base: ~64 bytes (Kind, offset, length, children)
- InlineSnapshotNode: +32 bytes (InlineFormatting)
- BlockSnapshotNode: +32 bytes (BlockFormatting)
- HyperlinkSnapshotNode: +8 bytes (URI reference)
- ListSnapshotNode: +12 bytes (marker style + start index)
- ImageSnapshotNode: +48 bytes (image data + metadata) For typical documents (100 pages, ~5000 nodes), snapshot size is ~400-600 KB.
Methods
| Name | Description |
|---|---|
| ChildrenOfKind | Enumerates child nodes matching a specific kind. |
| EnumerateDescendants | Enumerates this node and all descendants in pre-order (depth-first). |
| GetFormatMetadata | No summary available. |
| SetFormatMetadata | No summary available. |
ChildrenOfKind Method
Enumerates child nodes matching a specific kind.
public System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode> ChildrenOfKind(Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind kind)
Parameters
kind Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind
Returns
System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode>
EnumerateDescendants Method
Enumerates this node and all descendants in pre-order (depth-first).
public System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode> EnumerateDescendants()
Returns
System.Collections.Generic.IEnumerable<Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode>
GetFormatMetadata Method
public T GetFormatMetadata<T>()
Type Parameters
T
Returns
T
SetFormatMetadata Method
public void SetFormatMetadata<T>(T metadata)
Parameters
metadata T
Type Parameters
T
Properties
| Name | Description |
|---|---|
| Children | Child nodes. Empty array for leaf nodes. |
| CustomData | Extension-specific custom data for custom node kinds. Used by the builder path (Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshotBuilder) to propagate custom data from serializer importers to snapshot nodes. Must be immutable or thread-safe for background serialization. |
| EndOffset | Gets the absolute end offset (exclusive). |
| FormatMetadata | Format-specific metadata for round-trip fidelity. Serializers (RtfWriter, DocxWriter, etc.) can attach format-specific state here to preserve information that doesn't map cleanly to the semantic snapshot model. Not thread-safe; single-threaded access only. |
| IsBlock | Gets whether this is a block-level node. |
| IsInline | Gets whether this is an inline-level node. |
| IsLeaf | Gets whether this is a leaf node (no children). |
| IsTextRun | Gets whether this node represents a text run with actual content. |
| Kind | The kind of document element this node represents. |
| Length | Length of this node's content in characters. |
| StartOffset | Absolute offset in the document text where this node starts. |
| TextElementFormatting | Base-level formatting from Avalonia.Controls.Documents.RichTextElement. Carries font, foreground, background, and letter-spacing for every node type. |
Children Property
Child nodes. Empty array for leaf nodes.
public Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNodeChildren Children { get; set; }
CustomData Property
Extension-specific custom data for custom node kinds. Used by the builder path (Avalonia.Controls.Documents.Serialization.Snapshot.DocumentSnapshotBuilder) to propagate custom data from serializer importers to snapshot nodes. Must be immutable or thread-safe for background serialization.
public object CustomData { get; set; }
EndOffset Property
Gets the absolute end offset (exclusive).
public int EndOffset { get; set; }
FormatMetadata Property
Format-specific metadata for round-trip fidelity. Serializers (RtfWriter, DocxWriter, etc.) can attach format-specific state here to preserve information that doesn't map cleanly to the semantic snapshot model. Not thread-safe; single-threaded access only.
public object FormatMetadata { get; set; }
Remarks
Example: RTF uses twips for measurements and has 15 border types. The snapshot uses DIPs and 5 semantic border styles. Format metadata preserves original values for perfect round-trip fidelity.
The raw slot is internal: Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode.GetFormatMetadata<T> and Avalonia.Controls.Documents.Serialization.Snapshot.SnapshotNode.SetFormatMetadata<T>(<>) are the surface, and the type argument is what makes a reader's expectation legible at the call site.
IsBlock Property
Gets whether this is a block-level node.
public bool IsBlock { get; set; }
IsInline Property
Gets whether this is an inline-level node.
public bool IsInline { get; set; }
IsLeaf Property
Gets whether this is a leaf node (no children).
public bool IsLeaf { get; set; }
IsTextRun Property
Gets whether this node represents a text run with actual content.
public bool IsTextRun { get; set; }
Kind Property
The kind of document element this node represents.
public Avalonia.Controls.Documents.TextModel.TextDocumentNodeKind Kind { get; set; }
Length Property
Length of this node's content in characters.
public int Length { get; set; }
StartOffset Property
Absolute offset in the document text where this node starts.
public int StartOffset { get; set; }
TextElementFormatting Property
Base-level formatting from Avalonia.Controls.Documents.RichTextElement. Carries font, foreground, background, and letter-spacing for every node type.
public Avalonia.Controls.Documents.TextModel.Formatting.TextElementFormatting TextElementFormatting { get; set; }