Utf8YamlWriter Struct
Definition
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
outputIBufferWriter<byte>The buffer to which UTF-8 YAML is written.
Exceptions
- ArgumentNullException
outputis null.
Utf8YamlWriter(IBufferWriter<byte>, YamlWriterOptions)
Initializes a new instance of the Utf8YamlWriter struct with options.
public Utf8YamlWriter(IBufferWriter<byte> output, YamlWriterOptions options)
Parameters
outputIBufferWriter<byte>The buffer to which UTF-8 YAML is written.
optionsYamlWriterOptionsThe writer options.
Exceptions
- ArgumentNullException
outputis 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
valueboolThe boolean value.
WriteDouble(double)
Writes a floating-point scalar value.
public void WriteDouble(double value)
Parameters
valuedoubleThe 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
valuelongThe 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
namestringThe key text.
Exceptions
- ArgumentNullException
nameis 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
valuestringThe string value.
Exceptions
- ArgumentNullException
valueis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |