Table of Contents

YamlNode Class

Definition

Namespace
Bodu.Text.Yaml.Nodes
Assembly
Bodu.Text.Yaml.dll
Package
Bodu.Text.Yaml 1.0.0
Source
YamlNode.cs

Represents a node in a mutable YAML document object model, in the manner of System.Text.Json.Nodes.JsonNode.

public abstract class YamlNode
Inheritance
YamlNode
Derived
Inherited Members
Extension Methods

Remarks

The node tree is fully mutable: mappings (YamlObject), sequences (YamlArray), and scalars (YamlValue) can be created, edited, and re-serialized. A node may appear at most once in a tree.

Properties

this[int]

Gets or sets the child node at the specified sequence index.

public virtual YamlNode? this[int index] { get; set; }

Parameters

index int

The zero-based index.

Property Value

YamlNode

The child node, or null.

Exceptions

InvalidOperationException

The node is not a sequence.

this[string]

Gets or sets the child node mapped to the specified key.

public virtual YamlNode? this[string key] { get; set; }

Parameters

key string

The mapping key.

Property Value

YamlNode

The mapped node, or null.

Exceptions

InvalidOperationException

The node is not a mapping.

Methods

AsArray()

Returns this node as a YamlArray.

public YamlArray AsArray()

Returns

YamlArray

The node typed as a sequence.

Exceptions

InvalidOperationException

The node is not a sequence.

AsObject()

Returns this node as a YamlObject.

public YamlObject AsObject()

Returns

YamlObject

The node typed as a mapping.

Exceptions

InvalidOperationException

The node is not a mapping.

AsValue()

Returns this node as a YamlValue.

public YamlValue AsValue()

Returns

YamlValue

The node typed as a scalar.

Exceptions

InvalidOperationException

The node is not a scalar.

Parse(string)

Parses YAML text into a mutable node tree.

public static YamlNode? Parse(string yaml)

Parameters

yaml string

The YAML source.

Returns

YamlNode

The root node, or null when the document is empty/null.

Exceptions

ArgumentNullException

yaml is null.

YamlFormatException

The source is not valid YAML.

ToYamlString()

Serializes the node tree to YAML text.

public string ToYamlString()

Returns

string

The YAML representation of the node.

WriteTo(Utf8YamlWriter)

Writes this node to the given writer.

public abstract void WriteTo(Utf8YamlWriter writer)

Parameters

writer Utf8YamlWriter

The writer to emit into.

Applies to

ProductVersions
.NET8, 10