Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

YamlMapping

OfficeIMO.Yaml

Namespace
OfficeIMO.Yaml
Assembly
OfficeIMO.Yaml
Source revision
0eef6a5756b9 with working tree changes
Implements
IReadOnlyList<YamlMappingEntry> IReadOnlyCollection<YamlMappingEntry> IEnumerable<YamlMappingEntry> IEnumerable
Modifiers
sealed
Attributes
DefaultMember("Item")

A mapping node: block (key: value) or flow ({a: 1}). Entries keep source order, including equal keys a lenient YamlDuplicateKeyPolicy admitted.

Inheritance

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.

Accepted by parameters 1

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 it

Constructors

YamlMapping 2 overloads
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 required

Exceptions

  • ArgumentOutOfRangeException – style is not a collection style.

Methods

Add 2 overloads
public YamlNode Add(string key, YamlNode? value) #

Adds an entry at the end.

Parameters

key string required
value OfficeIMO.Yaml.YamlNode? required

Returns

YamlNode The value node, now in the mapping.

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 required
value OfficeIMO.Yaml.YamlNode? required

Returns

YamlNode The value node, now in the mapping.
public bool ContainsKey(string key) #

Returns whether a key has the given text, including merged keys where they apply.

Parameters

key string required

Returns

bool

Exceptions

  • ArgumentNullException – key is null.
public Enumerator GetEnumerator() #

Returns an enumerator over the entries as written that does not allocate.

Returns

Enumerator
public 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 required

Returns

int
Insert 2 overloads
public 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 required
key string required
value OfficeIMO.Yaml.YamlNode? required

Returns

YamlNode The value node, now in the mapping.

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 required
key OfficeIMO.Yaml.YamlNode required
value OfficeIMO.Yaml.YamlNode? required

Returns

YamlNode The value node, now in the mapping.
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 required
options OfficeIMO.Yaml.YamlMergeOptions? = null optional

Returns

YamlMergeReport The added, replaced and removed paths and the findings of the merge.

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 required

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 required

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 required
newKey string required

Returns

YamlScalar The key node.

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 required
The key text.
value OfficeIMO.Yaml.YamlNode? required
The value; null sets a null scalar. Strings, numbers and booleans convert implicitly.

Returns

YamlNode The node now at the key.

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 required
value OfficeIMO.Yaml.YamlNode? required

Returns

bool

Exceptions

  • ArgumentNullException – key is null.

Properties

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 required

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 required

Exceptions

  • ArgumentNullException – key is null.
  • KeyNotFoundException – Getting: no key has the text, including merged keys.