YamlMapping
OfficeIMO.Yaml
A mapping node: block (key: value) or flow ({a: 1}). Entries keep source order, including equal keys a lenient YamlDuplicateKeyPolicy admitted.
Inheritance
- YamlNode
- YamlMapping
Remarks
String-key lookups (the indexer, YamlMapping.TryGetValue, YamlMapping.ContainsKey and paths) are the mapping's typed view. They match scalar keys, including keys reached through an alias, by decoded text, so "a" and a are the same key, and they are O(1) after the first lookup builds an index. Under the YAML 1.1 schema, and under the core schema unless the load is strict, they also see the entries of << merge keys: the mapping's own keys win, then merged mappings in order. Enumeration and YamlMapping.Count show the tree as written; merges are never flattened into it.
Usage
Explore 6 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 5
- Method YamlAlias.AsMapping
- Method YamlMapping.AsMapping
- Method YamlNode.AsMapping
- Method YamlScalar.AsMapping
- Method YamlSequence.AsMapping
Accepted by parameters 1
- Method YamlMapping.Merge
Examples
YamlMapping spec = document.Select("spec")!.AsMapping();
spec["replicas"] = 3; // only the value's text changes
spec.Add("paused", false).SetComment("rollout hold");
spec.Remove("progressDeadlineSeconds"); // its comments and line go with itConstructors
public YamlMapping() #Creates an empty block mapping. Inside a flow collection it is written as flow.
public YamlMapping(YamlStyle style) #Creates an empty mapping with a style: YamlStyle.Block or YamlStyle.Flow ({a: 1}).
Parameters
- style OfficeIMO.Yaml.YamlStyle
Exceptions
ArgumentOutOfRangeException– style is not a collection style.
Methods
public YamlNode Add(string key, YamlNode? value) #Adds an entry at the end.
Parameters
- key string
- value OfficeIMO.Yaml.YamlNode?
Exceptions
ArgumentException– The mapping already has the key.InvalidOperationException– value already belongs to a collection.
public YamlNode Add(YamlNode key, YamlNode? value) #Adds an entry with a key node at the end, for keys with a chosen style, a tag, or a collection as key.
Parameters
- key OfficeIMO.Yaml.YamlNode
- value OfficeIMO.Yaml.YamlNode?
public bool ContainsKey(string key) #Returns whether a key has the given text, including merged keys where they apply.
Parameters
- key string
Returns
boolExceptions
ArgumentNullException– key is null.
public Enumerator GetEnumerator() #Returns an enumerator over the entries as written that does not allocate.
Returns
Enumeratorpublic int IndexOf(string key) #Returns the position of the mapping's own entry with the key text, or -1. Merged keys are not counted.
Parameters
- key string
Returns
intpublic YamlNode Insert(int index, string key, YamlNode? value) #Inserts an entry before the entry at index, or at the end when it equals YamlMapping.Count. The new entry takes the indentation, layout and quoting of its neighbors.
Parameters
- index int
- key string
- value OfficeIMO.Yaml.YamlNode?
Exceptions
ArgumentOutOfRangeException– index is outside 0..YamlMapping.Count.ArgumentException– The mapping already has the key.
public YamlNode Insert(int index, YamlNode key, YamlNode? value) #Inserts an entry with a key node; see YamlMapping.Insert.
Parameters
- index int
- key OfficeIMO.Yaml.YamlNode
- value OfficeIMO.Yaml.YamlNode?
public YamlMergeReport Merge(YamlMapping overlay, YamlMergeOptions? options = null) #Deep-merges an overlay mapping into this one with the rules of YamlDocument.Merge, for a subtree such as the result of YamlNode.Select. The overlay can come from another document or be a new mapping. Reported paths start at this document's root.
Parameters
- overlay OfficeIMO.Yaml.YamlMapping
- options OfficeIMO.Yaml.YamlMergeOptions? = null
Exceptions
ArgumentNullException– overlay is null.ArgumentException– overlay is this mapping, or is inside or around it.
public bool Remove(string key) #Removes the entry with the given key text, together with the comment lines above it, its line and its trailing comment. Neighbors keep their comments and blank lines. Merged keys are never removed from their source.
Parameters
- key string
Returns
bool Whether the mapping had the key.Exceptions
InvalidOperationException– Aliases elsewhere refer to an anchor inside the entry.
public void RemoveAt(int index) #Removes the entry at a position; see YamlMapping.Remove.
Parameters
- index int
Exceptions
ArgumentOutOfRangeException– index is outside the mapping.
public YamlScalar RenameKey(string key, string newKey) #Renames a key, keeping its entry's position, value and comments. The key keeps its quoting when that can represent the new text.
Parameters
- key string
- newKey string
Exceptions
KeyNotFoundException– The mapping has no key key of its own.ArgumentException– The mapping already has a key newKey.
public YamlNode Set(string key, YamlNode? value) #Sets the value of a key, adding the entry at the end when the mapping has no such key of its own. A key that only a << merge provides gets an entry of its own, which overrides the merged one; merged mappings are never edited. A scalar set over a scalar updates it in place, keeping its anchor, tag, comments and, for an equal value, its text; other values replace the node.
Parameters
- key string
- The key text.
- value OfficeIMO.Yaml.YamlNode?
- The value; null sets a null scalar. Strings, numbers and booleans convert implicitly.
Exceptions
InvalidOperationException– value already belongs to a collection.
public bool TryGetValue(string key, out YamlNode? value) #Gets the value of the key with the given text, looking through merge keys where they apply (see the remarks).
Parameters
- key string
- value OfficeIMO.Yaml.YamlNode?
Returns
boolExceptions
ArgumentNullException– key is null.
Inherited Methods
public YamlNode SetAnchor(string? name) #Parameters
- name string?
Returns
YamlNodepublic YamlNode SetComment(string? text) #Parameters
- text string?
Returns
YamlNodepublic YamlNode SetCommentBefore(string? text) #Parameters
- text string?
Returns
YamlNodepublic YamlNode SetSpaceBefore(bool value) #Parameters
- value bool
Returns
YamlNodeProperties
public int Count { get; } #Gets the number of entries as written, without merged entries.
public YamlMappingEntry this[int index] { get; } #Gets the entry at a zero-based position in source order.
Parameters
- index int
Exceptions
ArgumentOutOfRangeException– index is outside the mapping.
public YamlNode this[string key] { get; set; } #Gets the value of the key with the given text, or sets it as YamlMapping.Set does. Aliases are returned as YamlAlias nodes.
Parameters
- key string
Exceptions
ArgumentNullException– key is null.KeyNotFoundException– Getting: no key has the text, including merged keys.