YamlObject Class
Definition
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
keystringThe mapping key.
Property Value
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
keyis 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
Exceptions
- ArgumentNullException
keyis null.- ArgumentException
An entry with the same key already exists.
- InvalidOperationException
valuealready 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
keystringThe key to locate.
Returns
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
keystringThe key to remove.
Returns
TryGetValue(string, out YamlNode?)
Attempts to get the node mapped to the specified key.
public bool TryGetValue(string key, out YamlNode? value)
Parameters
Returns
WriteTo(Utf8YamlWriter)
Writes this node to the given writer.
public override void WriteTo(Utf8YamlWriter writer)
Parameters
writerUtf8YamlWriterThe 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
| Product | Versions |
|---|---|
| .NET | 8, 10 |