YamlDocument class

Represents the structure of a YAML value in a lightweight, read-only form.

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

public sealed class YamlDocument : IDisposable

Implements: IDisposable

Represents the structure of a YAML value in a lightweight, read-only form.

RemarksLink to this heading

This class utilizes resources from pooled memory to minimize the garbage collector (GC) impact in high-usage scenarios. Failure to properly Dispose this object will result in the memory not being returned to the pool, which will cause an increase in GC impact across various parts of the framework.

PropertiesLink to this heading

RootElementLink to this heading

The YamlElement representing the value of the document.

public YamlElement RootElement { get; }

MethodsLink to this heading

DisposeLink to this heading

public void Dispose();

ParseLink to this heading

Parse memory as UTF-8 encoded text representing a single YAML value into a YamlDocument.

public static YamlDocument Parse(ReadOnlyMemory<byte> utf8Yaml, YamlDocumentOptions options = default);

Parameters

  • utf8Yaml: YAML text to parse.
  • options: Options to control the reader behavior during parsing.

Returns: A YamlDocument representation of the YAML value.

Exception Condition
YamlException utf8Yaml does not represent a valid single YAML value.
ArgumentException options contains unsupported options.

The ReadOnlyMemory<T> value will be used for the entire lifetime of the YamlDocument object, and the caller must ensure that the data therein does not change during the object lifetime.

Because the input is considered to be text, a UTF-8 Byte-Order-Mark (BOM) must not be present.

Parse a sequence as UTF-8 encoded text representing a single YAML value into a YamlDocument.

public static YamlDocument Parse(ReadOnlySequence<byte> utf8Yaml, YamlDocumentOptions options = default);

Parameters

  • utf8Yaml: YAML text to parse.
  • options: Options to control the reader behavior during parsing.

Returns: A YamlDocument representation of the YAML value.

Exception Condition
YamlException utf8Yaml does not represent a valid single YAML value.
ArgumentException options contains unsupported options.

The ReadOnlySequence<T> may be used for the entire lifetime of the YamlDocument object, and the caller must ensure that the data therein does not change during the object lifetime.

Because the input is considered to be text, a UTF-8 Byte-Order-Mark (BOM) must not be present.

Parse a Stream as UTF-8 encoded data representing a single YAML value into a YamlDocument. The Stream will be read to completion.

public static YamlDocument Parse(Stream utf8Yaml, YamlDocumentOptions options = default);

Parameters

  • utf8Yaml: YAML data to parse.
  • options: Options to control the reader behavior during parsing.

Returns: A YamlDocument representation of the YAML value.

Exception Condition
YamlException utf8Yaml does not represent a valid single YAML value.
ArgumentException options contains unsupported options.

Parses text representing a single YAML value into a YamlDocument.

public static YamlDocument Parse(ReadOnlyMemory<char> yaml, YamlDocumentOptions options = default);

Parameters

  • yaml: YAML text to parse.
  • options: Options to control the reader behavior during parsing.

Returns: A YamlDocument representation of the YAML value.

Exception Condition
YamlException yaml does not represent a valid single YAML value.
ArgumentException options contains unsupported options.

The ReadOnlyMemory<T> value may be used for the entire lifetime of the YamlDocument object, and the caller must ensure that the data therein does not change during the object lifetime.

Parses text representing a single YAML value into a YamlDocument.

public static YamlDocument Parse(string yaml, YamlDocumentOptions options = default);

Parameters

  • yaml: YAML text to parse.
  • options: Options to control the reader behavior during parsing.

Returns: A YamlDocument representation of the YAML value.

Exception Condition
YamlException yaml does not represent a valid single YAML value.
ArgumentException options contains unsupported options.

ParseAsyncLink to this heading

Parse a Stream as UTF-8 encoded data representing a single YAML value into a YamlDocument. The Stream will be read to completion.

public static Task<YamlDocument> ParseAsync(Stream utf8Yaml, YamlDocumentOptions options = default, CancellationToken cancellationToken = default);

Parameters

  • utf8Yaml: YAML data to parse.
  • options: Options to control the reader behavior during parsing.
  • cancellationToken: The token to monitor for cancellation requests.

Returns: A Task to produce a YamlDocument representation of the YAML value.

Exception Condition
YamlException utf8Yaml does not represent a valid single YAML value.
ArgumentException options contains unsupported options.

ParseValueLink to this heading

Parses one YAML value (including objects or arrays) from the provided reader.

public static YamlDocument ParseValue(ref Utf8YamlReader reader);

Parameters

  • reader: The reader to read.

Returns: A YamlDocument representing the value (and nested values) read from the reader.

Exception Condition
ArgumentException reader is using unsupported options.
ArgumentException The current reader token does not start or represent a value.
YamlException A value could not be read from the reader.

If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.

Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

TryParseValueLink to this heading

Attempts to parse one YAML value (including objects or arrays) from the provided reader.

public static bool TryParseValue(ref Utf8YamlReader reader, out YamlDocument? document);

Parameters

  • reader: The reader to read.
  • document: Receives the parsed document.

Returns: true if a value was read and parsed into a YamlDocument, false if the reader ran out of data while parsing. All other situations result in an exception being thrown.

Exception Condition
ArgumentException reader is using unsupported options.
ArgumentException The current reader token does not start or represent a value.
YamlException A value could not be read from the reader.

If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.

Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, or false is returned, the reader is reset to the state it was in when the method was called.

This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.

WriteToLink to this heading

Write the document into the provided writer as a YAML value.

public void WriteTo(Utf8YamlWriter writer);

Parameters

  • writer:
Exception Condition
ArgumentNullException The writer parameter is null.
InvalidOperationException This YamlDocument.RootElement's YamlElement.ValueKind would result in an invalid YAML.
ObjectDisposedException The parent YamlDocument has been disposed.

A block-style writer keeps the source's styles (each collection's flow or block style, each scalar's and key's quoting or block style) where it can hold the text in them, unless YamlWriterOptions.IgnoreSourceStyles is set, which writes in the writer's own styles.

Generated from the XML documentation of the libraryBuilt with Douze

Esc to close