YamlNode Class
Definition
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
indexintThe zero-based index.
Property Value
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
keystringThe mapping key.
Property Value
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
yamlstringThe YAML source.
Returns
Exceptions
- ArgumentNullException
yamlis 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
writerUtf8YamlWriterThe writer to emit into.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |