YamlDocument Class

A read-only representation of a UTF-8 YAML stream: one row per node in a pooled array over the input bytes. Scalars are decoded only when asked for, and every node keeps the location of its text in the input.

public sealed class YamlDocument : IDisposable

Remarks

Dispose the document to return its buffers to the pool. Its nodes must not be used after that.

Implements

Properties

NameDescription
DocumentCountGets the number of documents of the stream.
RootGets the root node of the first document.
Utf8TextGets the UTF-8 input of the document.

DocumentCount

YamlDocument.cs

Gets the number of documents of the stream.

public int DocumentCount { get; }

Property value

int

Gets the root node of the first document.

public YamlElement Root { get; }

Property value

YamlElement

Exceptions

InvalidOperationException
The stream has no document.

Gets the UTF-8 input of the document.

public ReadOnlyMemory<byte> Utf8Text { get; }

Property value

ReadOnlyMemory<byte>

Methods

NameDescription
Dispose()Returns the buffers of the document to the pool.
GetDocumentRoot(int)Gets the root node of a document of the stream.
Parse(Stream, Utf8YamlReaderOptions)Reads a UTF-8 YAML stream to its end and parses it.
Parse(ReadOnlyMemory<byte>, Utf8YamlReaderOptions)Parses a UTF-8 YAML stream. The document keeps a reference to utf8Yaml, which must not change while it is used.
Parse(string, Utf8YamlReaderOptions)Parses a YAML stream.
WriteTo(Utf8YamlWriter)Writes every document of the stream, with its %TAG directives, each one after the first with a --- marker.

Returns the buffers of the document to the pool.

public void Dispose()

GetDocumentRoot(int)

YamlDocument.cs

Gets the root node of a document of the stream.

public YamlElement GetDocumentRoot(int index)

Parameters

index int

Returns

YamlElement

Parse overloads

Parse(Stream, Utf8YamlReaderOptions)

YamlDocument.cs

Reads a UTF-8 YAML stream to its end and parses it.

public static YamlDocument Parse(Stream utf8Yaml, Utf8YamlReaderOptions options = default)
Parameters
utf8Yaml Stream
options Utf8YamlReaderOptions
Returns

YamlDocument

Exceptions
ArgumentNullException
utf8Yaml is null.
YamlException
The input is not valid YAML.

Parse(ReadOnlyMemory<byte>, Utf8YamlReaderOptions)

YamlDocument.cs

Parses a UTF-8 YAML stream. The document keeps a reference to utf8Yaml, which must not change while it is used.

public static YamlDocument Parse(ReadOnlyMemory<byte> utf8Yaml, Utf8YamlReaderOptions options = default)
Parameters
utf8Yaml ReadOnlyMemory<byte>
options Utf8YamlReaderOptions
Returns

YamlDocument

Exceptions
YamlException
The input is not valid YAML.

Parse(string, Utf8YamlReaderOptions)

YamlDocument.cs

Parses a YAML stream.

public static YamlDocument Parse(string yaml, Utf8YamlReaderOptions options = default)
Parameters
yaml string
options Utf8YamlReaderOptions
Returns

YamlDocument

Exceptions
ArgumentNullException
yaml is null.
YamlException
The input is not valid YAML.

WriteTo(Utf8YamlWriter)

YamlDocument.cs

Writes every document of the stream, with its %TAG directives, each one after the first with a --- marker.

public void WriteTo(Utf8YamlWriter writer)

Parameters

writer Utf8YamlWriter
The destination.

Exceptions

ArgumentNullException
writer is null.

Remarks

See YamlElement.WriteTo. The tags are written with the handles of the directives.