YamlArray class
Represents a mutable YAML array.
Namespace: System.Text.Yaml.Nodes · Assembly: Styml.dll
public sealed class YamlArray : YamlNode, IList<YamlNode>
Inheritance: object → YamlNode → YamlArray
Implements: IList<YamlNode>
Represents a mutable YAML array.
RemarksLink to this heading
It is safe to perform multiple concurrent read operations on a YamlArray, but issues can occur if the collection is modified while it's being read.
ConstructorsLink to this heading
Initializes a new instance of the YamlArray class that is empty.
public YamlArray(YamlNodeOptions? options = null);
Parameters
options: Options to control the behavior.
Initializes a new instance of the YamlArray class that contains items from the specified params array.
public YamlArray(YamlNodeOptions options, params YamlNode?[] items);
Parameters
options: Options to control the behavior.items: The items to add to the newYamlArray.
Initializes a new instance of the YamlArray class that contains items from the specified params span.
public YamlArray(YamlNodeOptions options, ReadOnlySpan<YamlNode?> items);
Parameters
options: Options to control the behavior.items: The items to add to the newYamlArray.
Initializes a new instance of the YamlArray class that contains items from the specified array.
public YamlArray(params YamlNode?[] items);
Parameters
items: The items to add to the newYamlArray.
Initializes a new instance of the YamlArray class that contains items from the specified span.
public YamlArray(ReadOnlySpan<YamlNode?> items);
Parameters
items: The items to add to the newYamlArray.
PropertiesLink to this heading
CollectionStyleLink to this heading
Gets or sets the style this collection is written in by a block-style writer: YamlCollectionStyle.Flow for [a, b], YamlCollectionStyle.Block otherwise. A node parsed from YAML or JSON has its source's style (JSON's collections are flow); a new node is block. Inside a flow collection every collection is flow, and a JSON-compatible writer writes flow whatever is set. A source's style is not written under YamlWriterOptions.IgnoreSourceStyles; a style set here is.
public YamlCollectionStyle CollectionStyle { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not a collection style. |
CountLink to this heading
Gets the number of elements contained in the YamlArray.
public int Count { get; }
MethodsLink to this heading
AddLink to this heading
Adds an object to the end of the YamlArray.
public void Add<T>(T? value);
Type parameters
T: The type of object to be added.
Parameters
value: The object to be added to the end of theYamlArray.
Adds a YamlNode to the end of the YamlArray.
public void Add(YamlNode? item);
Parameters
ClearLink to this heading
Removes all elements from the YamlArray.
public void Clear();
ContainsLink to this heading
Determines whether an element is in the YamlArray.
public bool Contains(YamlNode? item);
Parameters
item: The object to locate in theYamlArray.
Returns: true if item is found in the YamlArray; otherwise, false.
CreateLink to this heading
Initializes a new instance of the YamlArray class that contains items from the specified YamlElement.
public static YamlArray? Create(YamlElement element, YamlNodeOptions? options = null);
Parameters
element: TheYamlElement.options: Options to control the behavior.
Returns: The new instance of the YamlArray class that contains items from the specified YamlElement.
| Exception | Condition |
|---|---|
| InvalidOperationException | The element is not a YamlValueKind.Array. |
GetEnumeratorLink to this heading
Returns an enumerator that iterates through the YamlArray.
public IEnumerator<YamlNode?> GetEnumerator();
Returns: A IEnumerator<T> for the YamlNode.
GetValuesLink to this heading
Returns an enumerable that wraps calls to YamlNode.GetValue.
public IEnumerable<T?> GetValues<T>();
Type parameters
T: The type of the value to obtain from theYamlValue.
Returns: An enumerable iterating over values of the array.
IndexOfLink to this heading
The object to locate in the YamlArray.
public int IndexOf(YamlNode? item);
Parameters
Returns: The index of item if found in the list; otherwise, -1.
InsertLink to this heading
Inserts an element into the YamlArray at the specified index.
public void Insert(int index, YamlNode? item);
Parameters
index: The zero-based index at whichitemshould be inserted.item: TheYamlNodeto insert.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | index is less than 0 or index is greater than YamlArray.Count. |
RemoveLink to this heading
Removes the first occurrence of a specific YamlNode from the YamlArray.
public bool Remove(YamlNode? item);
Parameters
Returns: true if item is successfully removed; otherwise, false.
RemoveAllLink to this heading
Removes all the elements that match the conditions defined by the specified predicate.
public int RemoveAll(Func<YamlNode?, bool> match);
Parameters
match: The predicate that defines the conditions of the elements to remove.
Returns: The number of elements removed from the YamlArray.
| Exception | Condition |
|---|---|
| ArgumentNullException | match is null. |
RemoveAtLink to this heading
Removes the element at the specified index of the YamlArray.
public void RemoveAt(int index);
Parameters
index: The zero-based index of the element to remove.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | index is less than 0 or index is greater than YamlArray.Count. |
RemoveRangeLink to this heading
Removes a range of elements from the YamlArray.
public void RemoveRange(int index, int count);
Parameters
index: The zero-based starting index of the range of elements to remove.count: The number of elements to remove.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | index or count is less than 0. |
| ArgumentException | index and count do not denote a valid range of elements in the YamlArray. |
WriteToLink to this heading
Write the YamlNode into the provided Utf8YamlWriter as YAML.
public override void WriteTo(Utf8YamlWriter writer, YamlSerializerOptions? options = null);
Parameters
writer: TheUtf8YamlWriter.options: Options to control the serialization behavior.
| Exception | Condition |
|---|---|
| ArgumentNullException | The writer parameter is null. |
A block-style writer keeps the source's styles (each collection's flow or block style, each scalar's and key's quoting or block style) where it can hold the text in them, unless YamlWriterOptions.IgnoreSourceStyles is set, which writes in the writer's own styles.