Utf8YamlWriter class

Provides a high-performance API for forward-only, non-cached writing of UTF-8 encoded YAML text.

Namespace: System.Text.Yaml ยท Assembly: Styml.dll

public sealed class Utf8YamlWriter : IAsyncDisposable, IDisposable

Implements: IAsyncDisposable, IDisposable

Provides a high-performance API for forward-only, non-cached writing of UTF-8 encoded YAML text.

RemarksLink to this heading

It writes the text sequentially with no caching and adheres to the YAML 1.2 specification by default (https://tools.ietf.org/html/rfc8259), with the exception of writing comments.

When the user attempts to write invalid YAML and validation is enabled, it throws an InvalidOperationException with a context specific error message.

To be able to format the output with indentation and whitespace OR to skip validation, create an instance of YamlWriterOptions and pass that in to the writer.

ConstructorsLink to this heading

Constructs a new Utf8YamlWriter instance with a specified bufferWriter.

public Utf8YamlWriter(IBufferWriter<byte> bufferWriter, YamlWriterOptions options = default);

Parameters

  • bufferWriter: An instance of IBufferWriter<T> used as a destination for writing YAML text into.
  • options: Defines the customized behavior of the Utf8YamlWriter By default, the Utf8YamlWriter writes YAML minimized (that is, with no extra whitespace) and validates that the YAML being written is structurally valid.
Exception Condition
ArgumentNullException Thrown when the instance of IBufferWriter<T> that is passed in is null.

Constructs a new Utf8YamlWriter instance with a specified utf8Yaml.

public Utf8YamlWriter(Stream utf8Yaml, YamlWriterOptions options = default);

Parameters

  • utf8Yaml: An instance of Stream used as a destination for writing YAML text into.
  • options: Defines the customized behavior of the Utf8YamlWriter By default, the Utf8YamlWriter writes YAML minimized (that is, with no extra whitespace) and validates that the YAML being written is structurally valid.
Exception Condition
ArgumentNullException Thrown when the instance of Stream that is passed in is null.

PropertiesLink to this heading

BytesCommittedLink to this heading

Returns the amount of bytes committed to the output by the Utf8YamlWriter so far.

public long BytesCommitted { get; }

In the case of IBufferwriter, this is how much the IBufferWriter has advanced. In the case of Stream, this is how much data has been written to the stream.

BytesPendingLink to this heading

Returns the amount of bytes written by the Utf8YamlWriter so far that have not yet been flushed to the output and committed.

public int BytesPending { get; }

CurrentDepthLink to this heading

Tracks the recursive depth of the nested objects / arrays within the YAML text written so far. This provides the depth of the current token.

public int CurrentDepth { get; }

OptionsLink to this heading

Gets the custom behavior when writing YAML using the Utf8YamlWriter which indicates whether to format the output while writing and whether to skip structural YAML validation or not.

public YamlWriterOptions Options { get; }

MethodsLink to this heading

DisposeLink to this heading

Commits any left over YAML text that has not yet been flushed and releases all resources used by the current instance.

public void Dispose();

In the case of IBufferWriter, this advances the underlying IBufferWriter<T> based on what has been written so far. In the case of Stream, this writes the data to the stream and flushes it.

The Utf8YamlWriter instance cannot be re-used after disposing.

DisposeAsyncLink to this heading

Asynchronously commits any left over YAML text that has not yet been flushed and releases all resources used by the current instance.

public ValueTask DisposeAsync();

In the case of IBufferWriter, this advances the underlying IBufferWriter<T> based on what has been written so far. In the case of Stream, this writes the data to the stream and flushes it.

The Utf8YamlWriter instance cannot be re-used after disposing.

FlushLink to this heading

Commits the YAML text written so far which makes it visible to the output destination.

public void Flush();
Exception Condition
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

In the case of IBufferWriter, this advances the underlying IBufferWriter<T> based on what has been written so far. In the case of Stream, this writes the data to the stream and flushes it.

FlushAsyncLink to this heading

Asynchronously commits the YAML text written so far which makes it visible to the output destination.

public Task FlushAsync(CancellationToken cancellationToken = default);
Exception Condition
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

In the case of IBufferWriter, this advances the underlying IBufferWriter<T> based on what has been written so far. In the case of Stream, this writes the data to the stream and flushes it asynchronously, while monitoring cancellation requests.

ResetLink to this heading

Resets the Utf8YamlWriter internal state so that it can be re-used.

public void Reset();
Exception Condition
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

The Utf8YamlWriter will continue to use the original writer options and the original output as the destination (either IBufferWriter<T> or Stream).

Resets the Utf8YamlWriter internal state so that it can be re-used with the new instance of Stream.

public void Reset(Stream utf8Yaml);

Parameters

  • utf8Yaml: An instance of Stream used as a destination for writing YAML text into.
Exception Condition
ArgumentNullException Thrown when the instance of Stream that is passed in is null.
ArgumentException Thrown when the instance of Stream that is passed in does not support writing.
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

The Utf8YamlWriter will continue to use the original writer options but now write to the passed in Stream as the new destination.

Resets the Utf8YamlWriter internal state so that it can be re-used with the new instance of Stream and the specified YamlWriterOptions.

public void Reset(Stream utf8Yaml, YamlWriterOptions options);

Parameters

  • utf8Yaml: An instance of Stream used as a destination for writing YAML text into.
  • options: Defines the customized behavior of the Utf8YamlWriter.
Exception Condition
ArgumentNullException Thrown when the instance of Stream that is passed in is null.
ArgumentException Thrown when the instance of Stream that is passed in does not support writing.
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

Resets the Utf8YamlWriter internal state so that it can be re-used with the new instance of IBufferWriter<T>.

public void Reset(IBufferWriter<byte> bufferWriter);

Parameters

  • bufferWriter: An instance of IBufferWriter<T> used as a destination for writing YAML text into.
Exception Condition
ArgumentNullException Thrown when the instance of IBufferWriter<T> that is passed in is null.
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

The Utf8YamlWriter will continue to use the original writer options but now write to the passed in IBufferWriter<T> as the new destination.

Resets the Utf8YamlWriter internal state so that it can be re-used with the new instance of IBufferWriter<T> and the specified YamlWriterOptions.

public void Reset(IBufferWriter<byte> bufferWriter, YamlWriterOptions options);

Parameters

  • bufferWriter: An instance of IBufferWriter<T> used as a destination for writing YAML text into.
  • options: Defines the customized behavior of the Utf8YamlWriter.
Exception Condition
ArgumentNullException Thrown when the instance of IBufferWriter<T> that is passed in is null.
ObjectDisposedException The instance of Utf8YamlWriter has been disposed.

WriteAliasPropertyNameLink to this heading

Writes an alias (*name :) as a mapping key.

public void WriteAliasPropertyName(string anchorName);

Parameters

  • anchorName: The anchor's name, without *.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a value cannot come next, or an anchor or a tag is pending (an alias has none).

Supported in block style only. Whether an earlier node defined the anchor is not checked; a reader reports an undefined alias.

Writes an alias (*name :) as a mapping key.

public void WriteAliasPropertyName(ReadOnlySpan<char> anchorName);

Parameters

  • anchorName: The anchor's name, without *.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a value cannot come next, or an anchor or a tag is pending (an alias has none).

Supported in block style only. Whether an earlier node defined the anchor is not checked; a reader reports an undefined alias.

Writes an alias (*name :) as a mapping key.

public void WriteAliasPropertyName(ReadOnlySpan<byte> utf8AnchorName);

Parameters

  • anchorName: The anchor's name, without *.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a value cannot come next, or an anchor or a tag is pending (an alias has none).

Supported in block style only. Whether an earlier node defined the anchor is not checked; a reader reports an undefined alias.

WriteAliasValueLink to this heading

Writes an alias (*name) as a value.

public void WriteAliasValue(string anchorName);

Parameters

  • anchorName: The anchor's name, without *.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a value cannot come next, or an anchor or a tag is pending (an alias has none).

Supported in block style only. Whether an earlier node defined the anchor is not checked; a reader reports an undefined alias.

Writes an alias (*name) as a value.

public void WriteAliasValue(ReadOnlySpan<char> anchorName);

Parameters

  • anchorName: The anchor's name, without *.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a value cannot come next, or an anchor or a tag is pending (an alias has none).

Supported in block style only. Whether an earlier node defined the anchor is not checked; a reader reports an undefined alias.

Writes an alias (*name) as a value.

public void WriteAliasValue(ReadOnlySpan<byte> utf8AnchorName);

Parameters

  • anchorName: The anchor's name, without *.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a value cannot come next, or an anchor or a tag is pending (an alias has none).

Supported in block style only. Whether an earlier node defined the anchor is not checked; a reader reports an undefined alias.

WriteAnchorLink to this heading

Writes an anchor (&name) for the next node: a value, a collection start, or a property name (the key node).

public void WriteAnchor(string anchorName);

Parameters

  • anchorName: The anchor's name, without &.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, no node may come next, or the next node already has an anchor.

The anchor is written at once, before the node. Before a property name, in any of the forms that write one (Utf8YamlWriter.WritePropertyName, WriteString(name, value), WriteStartObject(name)), it belongs to the key; to anchor the value of such a pair, write the name first.

Supported in block style only. Whether the name is defined before an alias uses it is not checked.

YAML allows any non-space character other than the flow indicators in a name, but some readers reject names with characters other than ASCII letters, digits, - and _ (SharpYaml, VYaml, and YamlDotNet inside a flow collection); keep to those for output such readers read.

Writes an anchor (&name) for the next node: a value, a collection start, or a property name (the key node).

public void WriteAnchor(ReadOnlySpan<char> anchorName);

Parameters

  • anchorName: The anchor's name, without &.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, no node may come next, or the next node already has an anchor.

The anchor is written at once, before the node. Before a property name, in any of the forms that write one (Utf8YamlWriter.WritePropertyName, WriteString(name, value), WriteStartObject(name)), it belongs to the key; to anchor the value of such a pair, write the name first.

Supported in block style only. Whether the name is defined before an alias uses it is not checked.

YAML allows any non-space character other than the flow indicators in a name, but some readers reject names with characters other than ASCII letters, digits, - and _ (SharpYaml, VYaml, and YamlDotNet inside a flow collection); keep to those for output such readers read.

Writes an anchor (&name) for the next node: a value, a collection start, or a property name (the key node).

public void WriteAnchor(ReadOnlySpan<byte> utf8AnchorName);

Parameters

  • anchorName: The anchor's name, without &.
Exception Condition
ArgumentException The name is not a valid anchor name.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, no node may come next, or the next node already has an anchor.

The anchor is written at once, before the node. Before a property name, in any of the forms that write one (Utf8YamlWriter.WritePropertyName, WriteString(name, value), WriteStartObject(name)), it belongs to the key; to anchor the value of such a pair, write the name first.

Supported in block style only. Whether the name is defined before an alias uses it is not checked.

YAML allows any non-space character other than the flow indicators in a name, but some readers reject names with characters other than ASCII letters, digits, - and _ (SharpYaml, VYaml, and YamlDotNet inside a flow collection); keep to those for output such readers read.

WriteBase64StringLink to this heading

Writes the pre-encoded property name and raw bytes value (as a Base64 encoded YAML string) as part of a name/value pair of a YAML object.

public void WriteBase64String(YamlEncodedText propertyName, ReadOnlySpan<byte> bytes);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • bytes: The binary data to write as Base64 encoded text.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the property name and raw bytes value (as a Base64 encoded YAML string) as part of a name/value pair of a YAML object.

public void WriteBase64String(string propertyName, ReadOnlySpan<byte> bytes);

Parameters

  • propertyName: The name of the property to write.
  • bytes: The binary data to write as Base64 encoded text.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and raw bytes value (as a Base64 encoded YAML string) as part of a name/value pair of a YAML object.

public void WriteBase64String(ReadOnlySpan<char> propertyName, ReadOnlySpan<byte> bytes);

Parameters

  • propertyName: The name of the property to write.
  • bytes: The binary data to write as Base64 encoded text.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and raw bytes value (as a Base64 encoded YAML string) as part of a name/value pair of a YAML object.

public void WriteBase64String(ReadOnlySpan<byte> utf8PropertyName, ReadOnlySpan<byte> bytes);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • bytes: The binary data to write as Base64 encoded text.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

WriteBase64StringSegmentLink to this heading

Writes the input bytes as a partial YAML string.

public void WriteBase64StringSegment(ReadOnlySpan<byte> value, bool isFinalSegment);

Parameters

  • value: The bytes to be written as a YAML string element of a YAML array.
  • isFinalSegment: Indicates that this is the final segment of the string.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown when validation is enabled if this would result in invalid YAML being written or if the previously written segment (if any) was not written with this same overload.

WriteBase64StringValueLink to this heading

Writes the raw bytes value as a Base64 encoded YAML string as an element of a YAML array.

public void WriteBase64StringValue(ReadOnlySpan<byte> bytes);

Parameters

  • bytes: The binary data to write as Base64 encoded text.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The bytes are encoded before writing.

WriteBooleanLink to this heading

Writes the pre-encoded property name and Boolean value (as a YAML literal "true" or "false") as part of a name/value pair of a YAML object.

public void WriteBoolean(YamlEncodedText propertyName, bool value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the property name and Boolean value (as a YAML literal "true" or "false") as part of a name/value pair of a YAML object.

public void WriteBoolean(string propertyName, bool value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and Boolean value (as a YAML literal "true" or "false") as part of a name/value pair of a YAML object.

public void WriteBoolean(ReadOnlySpan<char> propertyName, bool value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and Boolean value (as a YAML literal "true" or "false") as part of a name/value pair of a YAML object.

public void WriteBoolean(ReadOnlySpan<byte> utf8PropertyName, bool value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

WriteBooleanValueLink to this heading

Writes the Boolean value (as a YAML literal "true" or "false") as an element of a YAML array.

public void WriteBooleanValue(bool value);

Parameters

  • value: The value write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

WriteCollectionStyleLink to this heading

Requests a style for the next collection started (Utf8YamlWriter.WriteStartArray, Utf8YamlWriter.WriteStartObject and their forms with a property name): YamlCollectionStyle.Flow writes it on one line, [a, b] or {key: value}, with everything inside it.

public void WriteCollectionStyle(YamlCollectionStyle style);
Exception Condition
ArgumentOutOfRangeException style is not a collection style.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a style is already pending. A style followed by anything but a collection start also throws, at that call.

Inside a flow collection every collection is flow, whatever is requested. Supported in block style only.

WriteCommentValueLink to this heading

Writes a comment. In block style, endOfLine asks for it at the end of the current line (key: value # text), which is where it goes after a scalar value, an alias or an empty collection that is a mapping value or a sequence item; anywhere else, and for a comment of several lines, it is written on lines of its own, as Utf8YamlWriter.WriteCommentValue writes it. In JSON-compatible style endOfLine is ignored.

public void WriteCommentValue(string value, bool endOfLine);

Parameters

  • value: The comment's text.
  • endOfLine: Whether to put the comment at the end of the current line where it can go.
Exception Condition
ArgumentException The text is too large; in JSON-compatible style it contains */; in block style it holds a character a comment cannot hold.
ArgumentNullException value is null.

Writes a comment. In block style, endOfLine asks for it at the end of the current line (key: value # text), which is where it goes after a scalar value, an alias or an empty collection that is a mapping value or a sequence item; anywhere else, and for a comment of several lines, it is written on lines of its own, as Utf8YamlWriter.WriteCommentValue writes it. In JSON-compatible style endOfLine is ignored.

public void WriteCommentValue(ReadOnlySpan<char> value, bool endOfLine);

Parameters

  • value: The comment's text.
  • endOfLine: Whether to put the comment at the end of the current line where it can go.
Exception Condition
ArgumentException The text is too large; in JSON-compatible style it contains */; in block style it holds a character a comment cannot hold.
ArgumentNullException value is null.

Writes a comment. In block style, endOfLine asks for it at the end of the current line (key: value # text), which is where it goes after a scalar value, an alias or an empty collection that is a mapping value or a sequence item; anywhere else, and for a comment of several lines, it is written on lines of its own, as Utf8YamlWriter.WriteCommentValue writes it. In JSON-compatible style endOfLine is ignored.

public void WriteCommentValue(ReadOnlySpan<byte> utf8Value, bool endOfLine);

Parameters

  • value: The comment's text.
  • endOfLine: Whether to put the comment at the end of the current line where it can go.
Exception Condition
ArgumentException The text is too large; in JSON-compatible style it contains */; in block style it holds a character a comment cannot hold.
ArgumentNullException value is null.

Writes the string text value (as a YAML comment).

public void WriteCommentValue(string value);

Parameters

  • value: The value to write as a YAML comment within /*..*/.
Exception Condition
ArgumentException Thrown when the specified value is too large OR if the given string text value contains a comment delimiter (that is, */).
ArgumentNullException The value parameter is null.

The comment value is not escaped before writing.

Writes the text value (as a YAML comment).

public void WriteCommentValue(ReadOnlySpan<char> value);

Parameters

  • value: The value to write as a YAML comment within /*..*/.
Exception Condition
ArgumentException Thrown when the specified value is too large OR if the given text value contains a comment delimiter (that is, */).

The comment value is not escaped before writing.

Writes the UTF-8 text value (as a YAML comment).

public void WriteCommentValue(ReadOnlySpan<byte> utf8Value);

Parameters

  • utf8Value: The UTF-8 encoded value to be written as a YAML comment within /*..*/.
Exception Condition
ArgumentException Thrown when the specified value is too large OR if the given UTF-8 text value contains a comment delimiter (that is, */).

The comment value is not escaped before writing.

WriteDirectiveLink to this heading

Writes a directive, %YAML 1.2 or %TAG !e! tag:example.com,2000:, for the next document.

public void WriteDirective(string directive);

Parameters

  • directive: The directive's line, with its %.
Exception Condition
ArgumentException The text is not a %YAML or %TAG directive.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a directive cannot come here, or a second %YAML directive is written for the same document.

Directives come at the start of the output, after the end of a document (... is written first when the previous document is complete and not ended), or after another directive; Utf8YamlWriter.WriteDocumentStart must follow them. Supported in block style only.

Writes a directive, %YAML 1.2 or %TAG !e! tag:example.com,2000:, for the next document.

public void WriteDirective(ReadOnlySpan<char> directive);

Parameters

  • directive: The directive's line, with its %.
Exception Condition
ArgumentException The text is not a %YAML or %TAG directive.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a directive cannot come here, or a second %YAML directive is written for the same document.

Directives come at the start of the output, after the end of a document (... is written first when the previous document is complete and not ended), or after another directive; Utf8YamlWriter.WriteDocumentStart must follow them. Supported in block style only.

Writes a directive, %YAML 1.2 or %TAG !e! tag:example.com,2000:, for the next document.

public void WriteDirective(ReadOnlySpan<byte> utf8Directive);

Parameters

  • directive: The directive's line, with its %.
Exception Condition
ArgumentException The text is not a %YAML or %TAG directive.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, a directive cannot come here, or a second %YAML directive is written for the same document.

Directives come at the start of the output, after the end of a document (... is written first when the previous document is complete and not ended), or after another directive; Utf8YamlWriter.WriteDocumentStart must follow them. Supported in block style only.

WriteDocumentEndLink to this heading

Writes ..., the end of a document.

public void WriteDocumentEnd();
Exception Condition
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, the writer is inside a collection or a string, or after directives, or an anchor or a tag is pending.

A new document may follow, and so may directives. A root node written without Utf8YamlWriter.WriteDocumentStart first gets its --- anyway, which YAML 1.1 readers need there. Supported in block style only.

WriteDocumentStartLink to this heading

Writes ---, the start of a new document, and allows a new root value after a completed one.

public void WriteDocumentStart();
Exception Condition
InvalidOperationException The writer is inside a collection or a string, or after a property name, while validation is enabled.

The marker is written in both styles. Without it, a second root value is an error, as before.

WriteEndArrayLink to this heading

Writes the end of a YAML array.

public void WriteEndArray();
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

WriteEndObjectLink to this heading

Writes the end of a YAML object.

public void WriteEndObject();
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

WriteEndPropertyKeyLink to this heading

Ends the explicit key that Utf8YamlWriter.WriteStartPropertyKey started, and writes : on the next line; the entry's value follows.

public void WriteEndPropertyKey();
Exception Condition
InvalidOperationException The writer is in JSON-compatible style, or no explicit key is open at this level; or, while validation is enabled, its node is not written.

WriteNullLink to this heading

Writes the pre-encoded property name and the YAML literal "null" as part of a name/value pair of a YAML object.

public void WriteNull(YamlEncodedText propertyName);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the property name and the YAML literal "null" as part of a name/value pair of a YAML object.

public void WriteNull(string propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and the YAML literal "null" as part of a name/value pair of a YAML object.

public void WriteNull(ReadOnlySpan<char> propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and the YAML literal "null" as part of a name/value pair of a YAML object.

public void WriteNull(ReadOnlySpan<byte> utf8PropertyName);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

WriteNullValueLink to this heading

Writes the YAML literal "null" as an element of a YAML array.

public void WriteNullValue();
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

WriteNumberLink to this heading

Writes the pre-encoded property name and Decimal value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, decimal value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Decimal using the default StandardFormat (that is, 'G').

Writes the property name and Decimal value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, decimal value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Decimal using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the property name and Decimal value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, decimal value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Decimal using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the property name and Decimal value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, decimal value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Decimal using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the pre-encoded property name and Double value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, double value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Double using the default StandardFormat (that is, 'G').

Writes the property name and Double value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, double value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Double using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the property name and Double value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, double value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Double using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the property name and Double value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, double value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Double using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the pre-encoded property name and Single value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, float value);

Parameters

  • propertyName: The YAML-encoded name of the property to write..
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Single using the default StandardFormat (that is, 'G').

Writes the property name and Single value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, float value);

Parameters

  • propertyName: The name of the property to write..
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Single using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the property name and Single value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, float value);

Parameters

  • propertyName: The name of the property to write..
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Single using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the property name and Single value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, float value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Single using the default StandardFormat (that is, 'G'). The property name is escaped before writing.

Writes the pre-encoded property name and Int64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, long value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int64 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the property name and Int64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, long value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int64 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and Int64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, long value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int64 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and Int64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, long value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int64 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the pre-encoded property name and Int32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, int value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int32 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the property name and Int32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, int value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int32 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and Int32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, int value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int32 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the property name and Int32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, int value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int32 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the pre-encoded property name and UInt64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, ulong value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt64 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the property name and UInt64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, ulong value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt64 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and UInt64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, ulong value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt64 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and UInt64 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, ulong value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt64 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the pre-encoded property name and UInt32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(YamlEncodedText propertyName, uint value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt32 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the property name and UInt32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(string propertyName, uint value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt32 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and UInt32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<char> propertyName, uint value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt32 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

Writes the property name and UInt32 value (as a YAML number) as part of a name/value pair of a YAML object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, uint value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt32 using the default StandardFormat (that is, 'G'), for example: 32767. The property name is escaped before writing.

WriteNumberValueLink to this heading

Writes the Decimal value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(decimal value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Decimal using the default StandardFormat (that is, 'G').

Writes the Double value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(double value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Double using the default StandardFormat on .NET Core 3 or higher and 'G17' on any other framework.

Writes the Single value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(float value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Single using the default StandardFormat on .NET Core 3 or higher and 'G9' on any other framework.

Writes the Int32 value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(int value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int32 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the Int64 value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(long value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Int64 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the UInt32 value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(uint value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt32 using the default StandardFormat (that is, 'G'), for example: 32767.

Writes the UInt64 value (as a YAML number) as an element of a YAML array.

public void WriteNumberValue(ulong value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the UInt64 using the default StandardFormat (that is, 'G'), for example: 32767.

WritePropertyNameLink to this heading

Writes the pre-encoded property name (as a YAML string) as the first part of a name/value pair of a YAML object.

public void WritePropertyName(YamlEncodedText propertyName);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the property name (as a YAML string) as the first part of a name/value pair of a YAML object.

public void WritePropertyName(string propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name (as a YAML string) as the first part of a name/value pair of a YAML object.

public void WritePropertyName(ReadOnlySpan<char> propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the UTF-8 property name (as a YAML string) as the first part of a name/value pair of a YAML object.

public void WritePropertyName(ReadOnlySpan<byte> utf8PropertyName);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

WriteRawValueLink to this heading

Writes the input as YAML content. It is expected that the input content is a single complete YAML value.

public void WriteRawValue(string yaml, bool skipInputValidation = false);

Parameters

  • yaml: The raw YAML content to write.
  • skipInputValidation: Whether to validate if the input is a well-formed YAML payload.
Exception Condition
ArgumentNullException Thrown if yaml is null.
ArgumentException Thrown if the length of the input is zero or greater than 715,827,882 (Int32.MaxValue / 3).
YamlException Thrown if skipInputValidation is false, and the input is not a valid, complete, single YAML value according to the YAML 1.2 specification (https://yaml.org/spec/1.2.2/) or the input YAML exceeds a recursive depth of 64.

When writing untrused YAML values, do not set skipInputValidation to true as this can result in invalid YAML being written, and/or the overall payload being written to the writer instance being invalid. When using this method, the input content will be written to the writer destination as-is, unless validation fails (when it is enabled). The YamlWriterOptions.SkipValidation value for the writer instance is honored when using this method. The YamlWriterOptions.Indented and YamlWriterOptions.Encoder values for the writer instance are not applied when using this method.

Writes the input as YAML content. It is expected that the input content is a single complete YAML value.

public void WriteRawValue(ReadOnlySpan<char> yaml, bool skipInputValidation = false);

Parameters

  • yaml: The raw YAML content to write.
  • skipInputValidation: Whether to validate if the input is a well-formed YAML payload.
Exception Condition
ArgumentException Thrown if the length of the input is zero or greater than 715,827,882 (Int32.MaxValue / 3).
YamlException Thrown if skipInputValidation is false, and the input is not a valid, complete, single YAML value according to the YAML 1.2 specification (https://yaml.org/spec/1.2.2/) or the input YAML exceeds a recursive depth of 64.

When writing untrused YAML values, do not set skipInputValidation to true as this can result in invalid YAML being written, and/or the overall payload being written to the writer instance being invalid. When using this method, the input content will be written to the writer destination as-is, unless validation fails (when it is enabled). The YamlWriterOptions.SkipValidation value for the writer instance is honored when using this method. The YamlWriterOptions.Indented and YamlWriterOptions.Encoder values for the writer instance are not applied when using this method.

Writes the input as YAML content. It is expected that the input content is a single complete YAML value.

public void WriteRawValue(ReadOnlySpan<byte> utf8Yaml, bool skipInputValidation = false);

Parameters

  • utf8Yaml: The raw YAML content to write.
  • skipInputValidation: Whether to validate if the input is a well-formed YAML payload.
Exception Condition
ArgumentException Thrown if the length of the input is zero or greater than or equal to Int32.MaxValue.
YamlException Thrown if skipInputValidation is false, and the input is not a valid, complete, single YAML value according to the YAML 1.2 specification (https://yaml.org/spec/1.2.2/) or the input YAML exceeds a recursive depth of 64.

When writing untrused YAML values, do not set skipInputValidation to true as this can result in invalid YAML being written, and/or the overall payload being written to the writer instance being invalid. When using this method, the input content will be written to the writer destination as-is, unless validation fails (when it is enabled). The YamlWriterOptions.SkipValidation value for the writer instance is honored when using this method. The YamlWriterOptions.Indented and YamlWriterOptions.Encoder values for the writer instance are not applied when using this method.

Writes the input as YAML content. It is expected that the input content is a single complete YAML value.

public void WriteRawValue(ReadOnlySequence<byte> utf8Yaml, bool skipInputValidation = false);

Parameters

  • utf8Yaml: The raw YAML content to write.
  • skipInputValidation: Whether to validate if the input is a well-formed YAML payload.
Exception Condition
ArgumentException Thrown if the length of the input is zero or equal to Int32.MaxValue.
YamlException Thrown if skipInputValidation is false, and the input is not a valid, complete, single YAML value according to the YAML 1.2 specification (https://yaml.org/spec/1.2.2/) or the input YAML exceeds a recursive depth of 64.

When writing untrused YAML values, do not set skipInputValidation to true as this can result in invalid YAML being written, and/or the overall payload being written to the writer instance being invalid. When using this method, the input content will be written to the writer destination as-is, unless validation fails (when it is enabled). The YamlWriterOptions.SkipValidation value for the writer instance is honored when using this method. The YamlWriterOptions.Indented and YamlWriterOptions.Encoder values for the writer instance are not applied when using this method.

WriteScalarStyleLink to this heading

Requests a scalar style for the next string value or property name. In block style the request is honoured where the string allows it; in JSON-compatible style it is ignored.

public void WriteScalarStyle(YamlScalarStyle style);

Parameters

Exception Condition
ArgumentOutOfRangeException style is not a scalar style.
InvalidOperationException A hint is already pending, while validation is enabled. A hint followed by a node that is not a string value or a property name also throws, at that node.

The hint applies to the next node. A property name is a key node, so a hint before Utf8YamlWriter.WritePropertyName styles the key. In the forms that write a property name and a value in one call, the hint applies to the value.

The hint is a request: YamlScalarStyle.Plain on a string that cannot be plain is written double-quoted, and YamlScalarStyle.Literal or YamlScalarStyle.Folded on a string without a line break, or with a character a block scalar cannot hold, is written as it would be without the hint. YamlScalarStyle.SingleQuoted on a string with a line break is written over several lines (a line break as an empty line, M7b), except inside a flow collection or when the string has a tab, a carriage return or a space next to a line break, where it is double-quoted.

WriteStartArrayLink to this heading

Writes the beginning of a YAML array.

public void WriteStartArray();
Exception Condition
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

Writes the beginning of a YAML array with a pre-encoded property name as the key.

public void WriteStartArray(YamlEncodedText propertyName);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
Exception Condition
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

Writes the beginning of a YAML array with a property name as the key.

public void WriteStartArray(ReadOnlySpan<byte> utf8PropertyName);

Parameters

  • utf8PropertyName: The UTF-8 encoded property name of the YAML array to be written.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the beginning of a YAML array with a property name as the key.

public void WriteStartArray(string propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the beginning of a YAML array with a property name as the key.

public void WriteStartArray(ReadOnlySpan<char> propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

WriteStartObjectLink to this heading

Writes the beginning of a YAML object.

public void WriteStartObject();
Exception Condition
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

Writes the beginning of a YAML object with a pre-encoded property name as the key.

public void WriteStartObject(YamlEncodedText propertyName);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
Exception Condition
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

Writes the beginning of a YAML object with a property name as the key.

public void WriteStartObject(ReadOnlySpan<byte> utf8PropertyName);

Parameters

  • utf8PropertyName: The UTF-8 encoded property name of the YAML object to be written.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the beginning of a YAML object with a property name as the key.

public void WriteStartObject(string propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the beginning of a YAML object with a property name as the key.

public void WriteStartObject(ReadOnlySpan<char> propertyName);

Parameters

  • propertyName: The name of the property to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown when the depth of the YAML has exceeded the maximum depth of 1000 OR if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

WriteStartPropertyKeyLink to this heading

Starts an explicit key (?): exactly one node follows, a scalar or a collection, and becomes the key of the next entry; Utf8YamlWriter.WriteEndPropertyKey ends it, and the entry's value follows as after a property name.

public void WriteStartPropertyKey();
Exception Condition
InvalidOperationException The writer is in JSON-compatible style, or the depth would exceed the maximum; or, while validation is enabled, a property name cannot come next, or an anchor or a tag is pending.

The key's node may have an anchor or a tag, written after this call. Its level counts toward YamlWriterOptions.MaxDepth. Supported in block style only.

WriteStringLink to this heading

Writes the pre-encoded property name and DateTime value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, DateTime value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTime using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000. The property name should already be escaped when the instance of YamlEncodedText was created.

Writes the property name and DateTime value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, DateTime value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTime using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000. The property name is escaped before writing.

Writes the property name and DateTime value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, DateTime value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTime using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000. The property name is escaped before writing.

Writes the property name and DateTime value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, DateTime value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTime using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000. The property name is escaped before writing.

Writes the pre-encoded property name and DateTimeOffset value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, DateTimeOffset value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTimeOffset using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000-07:00.

Writes the property name and DateTimeOffset value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, DateTimeOffset value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTimeOffset using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000-07:00. The property name is escaped before writing.

Writes the property name and DateTimeOffset value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, DateTimeOffset value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTimeOffset using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000-07:00. The property name is escaped before writing.

Writes the property name and DateTimeOffset value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, DateTimeOffset value);

Parameters

  • utf8PropertyName: The UTF-8 encoded property name of the YAML object to be written.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTimeOffset using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000-07:00. The property name is escaped before writing.

Writes the pre-encoded property name and Guid value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, Guid value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Guid using the default StandardFormat (that is, 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn.

Writes the property name and Guid value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, Guid value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Guid using the default StandardFormat (that is, 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn. The property name is escaped before writing.

Writes the property name and Guid value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, Guid value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Guid using the default StandardFormat (that is, 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn. The property name is escaped before writing.

Writes the property name and Guid value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, Guid value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Guid using the default StandardFormat (that is, 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn. The property name is escaped before writing.

Writes the pre-encoded property name and pre-encoded value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, YamlEncodedText value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The YAML-encoded value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the property name and pre-encoded value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, YamlEncodedText value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The YAML-encoded value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and string text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, string? value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

If value is null the YAML null value is written, as if Utf8YamlWriter.WriteNull were called.

Writes the property name and text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, ReadOnlySpan<char> value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

Writes the UTF-8 property name and UTF-8 text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, ReadOnlySpan<byte> utf8Value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • utf8Value: The UTF-8 encoded value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

Writes the pre-encoded property name and string text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, string? value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The value is escaped before writing.

If value is null the YAML null value is written, as if Utf8YamlWriter.WriteNull was called.

Writes the pre-encoded property name and text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, ReadOnlySpan<char> value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The value is escaped before writing.

Writes the property name and text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, ReadOnlySpan<char> value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

Writes the UTF-8 property name and text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, ReadOnlySpan<char> value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

Writes the pre-encoded property name and UTF-8 text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(YamlEncodedText propertyName, ReadOnlySpan<byte> utf8Value);

Parameters

  • propertyName: The YAML-encoded name of the property to write.
  • utf8Value: The UTF-8 encoded value to write.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The value is escaped before writing.

Writes the property name and UTF-8 text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(string propertyName, ReadOnlySpan<byte> utf8Value);

Parameters

  • propertyName: The name of the property to write.
  • utf8Value: The UTF-8 encoded value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
ArgumentNullException The propertyName parameter is null.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

Writes the property name and UTF-8 text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, ReadOnlySpan<byte> utf8Value);

Parameters

  • propertyName: The name of the property to write.
  • utf8Value: The UTF-8 encoded value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value is escaped before writing.

Writes the property name and pre-encoded value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, YamlEncodedText value);

Parameters

  • propertyName: The name of the property to write.
  • value: The YAML-encoded value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the property name and string text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<char> propertyName, string? value);

Parameters

  • propertyName: The name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value are escaped before writing.

If value is null the YAML null value is written, as if Utf8YamlWriter.WriteNull was called.

Writes the UTF-8 property name and pre-encoded value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, YamlEncodedText value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The YAML-encoded value to write.
Exception Condition
ArgumentException Thrown when the specified property name is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name is escaped before writing.

Writes the UTF-8 property name and string text value (as a YAML string) as part of a name/value pair of a YAML object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, string? value);

Parameters

  • utf8PropertyName: The UTF-8 encoded name of the property to write.
  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified property name or value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The property name and value are escaped before writing.

If value is null the YAML null value is written, as if Utf8YamlWriter.WriteNull was called.

WriteStringValueLink to this heading

Writes the DateTime value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(DateTime value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTime using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000.

Writes the DateTimeOffset value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(DateTimeOffset value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the DateTimeOffset using the round-trippable ('O') StandardFormat , for example: 2017-06-12T05:30:45.7680000-07:00.

Writes the Guid value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(Guid value);

Parameters

  • value: The value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the Guid using the default StandardFormat (that is, 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn.

Writes the pre-encoded text value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(YamlEncodedText value);

Parameters

  • value: The YAML-encoded value to write.
Exception Condition
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

Writes the string text value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(string? value);

Parameters

  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The value is escaped before writing.

If value is null the YAML null value is written, as if Utf8YamlWriter.WriteNullValue was called.

Writes the text value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(ReadOnlySpan<char> value);

Parameters

  • value: The value to write.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The value is escaped before writing.

Writes the UTF-8 text value (as a YAML string) as an element of a YAML array.

public void WriteStringValue(ReadOnlySpan<byte> utf8Value);

Parameters

  • utf8Value: The UTF-8 encoded value to be written as a YAML string element of a YAML array.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown if this would result in invalid YAML being written (while validation is enabled).

The value is escaped before writing.

WriteStringValueSegmentLink to this heading

Writes the text value segment as a partial YAML string.

public void WriteStringValueSegment(ReadOnlySpan<char> value, bool isFinalSegment);

Parameters

  • value: The value to write.
  • isFinalSegment: Indicates that this is the final segment of the string.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown when validation is enabled if this would result in invalid YAML being written or if the previously written segment (if any) was not written with this same overload.

The value is escaped before writing.

Writes the UTF-8 text value segment as a partial YAML string.

public void WriteStringValueSegment(ReadOnlySpan<byte> value, bool isFinalSegment);

Parameters

  • value: The UTF-8 encoded value to be written as a YAML string element of a YAML array.
  • isFinalSegment: Indicates that this is the final segment of the string.
Exception Condition
ArgumentException Thrown when the specified value is too large.
InvalidOperationException Thrown when validation is enabled if this would result in invalid YAML being written or if the previously written segment (if any) was not written with this same overload.

The value is escaped before writing.

WriteTagLink to this heading

Writes a tag for the next node: a value, a collection start, or a property name (the key node), as Utf8YamlWriter.WriteAnchor does.

public void WriteTag(string tag);

Parameters

  • tag: The tag as written: !, !foo, !!str, !e!foo (after a %TAG directive for !e!) or !<tag:example.com,2000:foo>. It is checked, not expanded.
Exception Condition
ArgumentException The tag is not valid tag syntax.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, no node may come next, or the next node already has a tag.

Supported in block style only.

Writes a tag for the next node: a value, a collection start, or a property name (the key node), as Utf8YamlWriter.WriteAnchor does.

public void WriteTag(ReadOnlySpan<char> tag);

Parameters

  • tag: The tag as written: !, !foo, !!str, !e!foo (after a %TAG directive for !e!) or !<tag:example.com,2000:foo>. It is checked, not expanded.
Exception Condition
ArgumentException The tag is not valid tag syntax.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, no node may come next, or the next node already has a tag.

Supported in block style only.

Writes a tag for the next node: a value, a collection start, or a property name (the key node), as Utf8YamlWriter.WriteAnchor does.

public void WriteTag(ReadOnlySpan<byte> utf8Tag);

Parameters

  • tag: The tag as written: !, !foo, !!str, !e!foo (after a %TAG directive for !e!) or !<tag:example.com,2000:foo>. It is checked, not expanded.
Exception Condition
ArgumentException The tag is not valid tag syntax.
InvalidOperationException The writer is in JSON-compatible style; or, while validation is enabled, no node may come next, or the next node already has a tag.

Supported in block style only.

Generated from the XML documentation of the libraryBuilt with Douze

Esc to close