Table of Contents

YamlElement Struct

Definition

Namespace
Bodu.Text.Yaml.Document
Assembly
Bodu.Text.Yaml.dll
Package
Bodu.Text.Yaml 1.0.0
Source
YamlElement.MappingEnumerator.cs

Represents a single node within a YamlDocument as a lightweight, read-only view, in the manner of System.Text.Json.JsonElement.

public readonly struct YamlElement
Inherited Members
Extension Methods

Remarks

An element is a small value type that refers back to its owning document and a node index. It is valid only while the owning document has not been disposed.

Properties

this[int]

Gets the element at the specified position within a sequence node.

public YamlElement this[int index] { get; }

Parameters

index int

The zero-based element position.

Property Value

YamlElement

The element view at the position.

Exceptions

InvalidOperationException

The node is not a sequence.

ArgumentOutOfRangeException

index is out of range.

ScalarStyle

Gets the presentation style of the node when it is a scalar.

public YamlScalarStyle ScalarStyle { get; }

Property Value

YamlScalarStyle

The scalar style, or Any for non-scalar nodes.

ValueKind

Gets the value kind of the node.

public YamlValueKind ValueKind { get; }

Property Value

YamlValueKind

The resolved value kind.

Methods

EnumerateMapping()

Returns an enumerator over the key/value pairs of a mapping node.

public YamlElement.MappingEnumerator EnumerateMapping()

Returns

YamlElement.MappingEnumerator

A mapping enumerator.

Exceptions

InvalidOperationException

The node is not a mapping.

EnumerateSequence()

Returns an enumerator over the elements of a sequence node.

public YamlElement.SequenceEnumerator EnumerateSequence()

Returns

YamlElement.SequenceEnumerator

A sequence enumerator.

Exceptions

InvalidOperationException

The node is not a sequence.

GetBoolean()

Returns the boolean value of a boolean scalar node.

public bool GetBoolean()

Returns

bool

The boolean value.

Exceptions

InvalidOperationException

The node is not a boolean scalar.

GetDouble()

Returns the floating-point value of a numeric scalar node.

public double GetDouble()

Returns

double

The double-precision value.

Exceptions

InvalidOperationException

The node is not a numeric scalar.

GetInt64()

Returns the integer value of an integer scalar node.

public long GetInt64()

Returns

long

The 64-bit integer value.

Exceptions

InvalidOperationException

The node is not an integer scalar.

GetProperty(string)

Returns the value associated with a key in a mapping node.

public YamlElement GetProperty(string propertyName)

Parameters

propertyName string

The key to look up.

Returns

YamlElement

The element view of the mapped value.

Exceptions

InvalidOperationException

The node is not a mapping.

KeyNotFoundException

The key is not present.

GetSequenceLength()

Returns the number of elements in a sequence node.

public int GetSequenceLength()

Returns

int

The element count.

Exceptions

InvalidOperationException

The node is not a sequence.

GetString()

Returns the string value of a string scalar node.

public string GetString()

Returns

string

The string value.

Exceptions

InvalidOperationException

The node is not a string scalar.

ToString()

Returns a textual representation of the element's value.

public override string ToString()

Returns

string

The decoded scalar value, or the kind name for containers.

TryGetProperty(string, out YamlElement)

Attempts to return the value associated with a key in a mapping node.

public bool TryGetProperty(string propertyName, out YamlElement value)

Parameters

propertyName string

The key to look up.

value YamlElement

When the method returns true, the mapped value.

Returns

bool

true when the key is present; otherwise false.

Exceptions

InvalidOperationException

The node is not a mapping.

WriteTo(Utf8YamlWriter)

Writes this element's value to the supplied writer at the writer's current position.

public void WriteTo(Utf8YamlWriter writer)

Parameters

writer Utf8YamlWriter

The destination writer.

Remarks

A scalar element writes its decoded value, a sequence writes its items in order, and a mapping writes its key/value pairs in stored order. Aliases were resolved when the document was parsed, so the emitted text is the fully composed tree.

Exceptions

InvalidOperationException

Thrown when this element is the default value and belongs to no document.

ObjectDisposedException

Thrown when the owning document has been disposed.

Applies to

ProductVersions
.NET8, 10