Table of Contents

YamlObject Class

Definition

Namespace
Bodu.Text.Yaml.Nodes
Assembly
Bodu.Text.Yaml.dll
Package
Bodu.Text.Yaml 1.3.0
Source
YamlObject.cs

Represents a mutable YAML mapping node whose entries preserve insertion order.

public sealed class YamlObject : YamlNode, IEnumerable<KeyValuePair<string, YamlNode?>>, IEnumerable
Inheritance
YamlObject
Implements
Inherited Members
Extension Methods

Remarks

A node may appear at most once in a tree. Adding or assigning a value that already belongs to a container, this mapping included, throws an InvalidOperationException; removing an entry or replacing its value detaches the value so that it can be added elsewhere. Adding the mapping to itself or to one of its own descendants throws an InvalidOperationException as well.

Constructors

YamlObject()

public YamlObject()

Properties

Count

Gets the number of entries in the mapping.

public int Count { get; }

Property Value

int

The entry count.

this[string]

Gets or sets the node mapped to the specified key, adding it when absent.

public override YamlNode? this[string key] { get; set; }

Parameters

key string

The mapping key.

Property Value

YamlNode

The mapped node, or null.

Remarks

Assigning over an entry detaches the replaced node, so that it can be added elsewhere. Assigning an entry's value over itself leaves the mapping unchanged.

Exceptions

ArgumentNullException

key is null.

InvalidOperationException

The assigned node already belongs to a container, and is not the value mapped to key; or the assigned node is this mapping or one of its ancestors.

Keys

Gets the keys of the mapping in insertion order.

public IReadOnlyList<string> Keys { get; }

Property Value

IReadOnlyList<string>

The ordered keys.

Methods

Add(string, YamlNode?)

Adds an entry to the mapping.

public void Add(string key, YamlNode? value)

Parameters

key string

The entry key.

value YamlNode

The entry value.

Exceptions

ArgumentNullException

key is null.

ArgumentException

An entry with the same key already exists.

InvalidOperationException

value already belongs to a container, or is this mapping or one of its ancestors.

ContainsKey(string)

Determines whether the mapping contains the specified key.

public bool ContainsKey(string key)

Parameters

key string

The key to locate.

Returns

bool

true when the key is present.

GetEnumerator()

Returns an enumerator over the entries in insertion order.

public IEnumerator<KeyValuePair<string, YamlNode?>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, YamlNode>>

The entry enumerator.

Remove(string)

Removes the entry with the specified key, detaching its value.

public bool Remove(string key)

Parameters

key string

The key to remove.

Returns

bool

true when an entry was removed.

TryGetValue(string, out YamlNode?)

Attempts to get the node mapped to the specified key.

public bool TryGetValue(string key, out YamlNode? value)

Parameters

key string

The key to locate.

value YamlNode

When the method returns true, the mapped node.

Returns

bool

true when the key is present.

WriteTo(Utf8YamlWriter)

Writes this node to the given writer.

public override void WriteTo(Utf8YamlWriter writer)

Parameters

writer Utf8YamlWriter

The writer to emit into.

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerator IEnumerable.GetEnumerator()

Returns

IEnumerator

An IEnumerator object that can be used to iterate through the collection.

Applies to

ProductVersions
.NET8, 10