Table of Contents

Utf8YamlWriter Struct

Definition

Namespace
Bodu.Text.Yaml.Writer
Assembly
Bodu.Text.Yaml.dll
Package
Bodu.Text.Yaml 1.0.0
Source
Utf8YamlWriter.cs

Provides a forward-only writer that emits a YAML document in block style to a UTF-8 buffer, in the manner of Utf8JsonWriter.

public ref struct Utf8YamlWriter
Inherited Members

Remarks

The writer emits block mappings and sequences with configurable indentation, choosing the most compact safe scalar presentation for each value (plain when unambiguous, otherwise double-quoted). Empty mappings and sequences are emitted in the flow forms {} and [] so they round-trip as empty collections rather than null.

The writer is a ref struct and cannot be boxed, stored on the heap, or captured by a lambda. Its mutable state lives behind a single shared reference, so passing the writer by value hands the callee the same in-progress document rather than an independent copy.

Constructors

Utf8YamlWriter(IBufferWriter<byte>)

Initializes a new instance of the Utf8YamlWriter struct.

public Utf8YamlWriter(IBufferWriter<byte> output)

Parameters

output IBufferWriter<byte>

The buffer to which UTF-8 YAML is written.

Exceptions

ArgumentNullException

output is null.

Utf8YamlWriter(IBufferWriter<byte>, YamlWriterOptions)

Initializes a new instance of the Utf8YamlWriter struct with options.

public Utf8YamlWriter(IBufferWriter<byte> output, YamlWriterOptions options)

Parameters

output IBufferWriter<byte>

The buffer to which UTF-8 YAML is written.

options YamlWriterOptions

The writer options.

Exceptions

ArgumentNullException

output is null.

ArgumentException

The options specify an unsupported newline string.

ArgumentOutOfRangeException

The options specify an out-of-range indentation width.

Methods

WriteBoolean(bool)

Writes a boolean scalar value.

public void WriteBoolean(bool value)

Parameters

value bool

The boolean value.

WriteDouble(double)

Writes a floating-point scalar value.

public void WriteDouble(double value)

Parameters

value double

The floating-point value.

WriteEndMapping()

Ends the current block mapping.

public void WriteEndMapping()

Exceptions

InvalidOperationException

There is no open mapping to close.

WriteEndSequence()

Ends the current block sequence.

public void WriteEndSequence()

Exceptions

InvalidOperationException

There is no open sequence to close.

WriteInteger(long)

Writes an integer scalar value.

public void WriteInteger(long value)

Parameters

value long

The integer value.

WriteNull()

Writes a null scalar value.

public void WriteNull()

WritePropertyName(string)

Writes a mapping key. The next write supplies its value.

public void WritePropertyName(string name)

Parameters

name string

The key text.

Exceptions

ArgumentNullException

name is null.

InvalidOperationException

The current container is not a mapping, or a key is already pending.

WriteStartMapping()

Begins a block mapping at the current value position.

public void WriteStartMapping()

WriteStartSequence()

Begins a block sequence at the current value position.

public void WriteStartSequence()

WriteString(string)

Writes a string scalar value.

public void WriteString(string value)

Parameters

value string

The string value.

Exceptions

ArgumentNullException

value is null.

Applies to

ProductVersions
.NET8, 10