YamlNode class
The base class that represents a single node within a mutable YAML document.
Namespace: System.Text.Yaml.Nodes ยท Assembly: Styml.dll
public abstract class YamlNode
Derived: YamlArray, YamlObject, YamlValue
The base class that represents a single node within a mutable YAML document.
PropertiesLink to this heading
AnchorLink to this heading
Gets or sets the node's anchor (&name, without the &), or null.
public string? Anchor { get; set; }
| Exception | Condition |
|---|---|
| ArgumentException | The value is empty. |
A node made from a YamlDocument keeps its anchor. A node made through an alias is a copy of the anchored node and has no anchor of its own. A block-style writer writes the anchor; a JSON-compatible one does not. An alias that is still part of an unedited element (inside a child that was not changed, or inside a copy's content) is written as that element writes it: as an alias when its anchor is inside the element, otherwise as the anchored node with its anchor, which redefines the anchor at that point (YAML allows it; the tree re-reads equal).
OptionsLink to this heading
Options to control the behavior.
public YamlNodeOptions? Options { get; }
ParentLink to this heading
Gets the parent YamlNode. If there is no parent, null is returned. A parent can either be a YamlObject or a YamlArray.
public YamlNode? Parent { get; }
RootLink to this heading
Gets the root YamlNode.
public YamlNode Root { get; }
The current node is returned if it is a root.
TagLink to this heading
Gets or sets the node's tag as written (!local, !!str), or null.
public string? Tag { get; set; }
| Exception | Condition |
|---|---|
| ArgumentException | The value is empty. |
A node made from a YamlDocument keeps its tag. A block-style writer writes the tag; a JSON-compatible one does not.
this[]Link to this heading
Gets or sets the element at the specified index.
public YamlNode? this[int index] { get; set; }
Parameters
index: The zero-based index of the element to get or set.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | index is less than 0 or index is greater than the number of properties. |
| InvalidOperationException | The current YamlNode is not a YamlArray or YamlObject. |
Gets or sets the element with the specified property name. If the property is not found, null is returned.
public YamlNode? this[string propertyName] { get; set; }
Parameters
propertyName: The name of the property to return.
| Exception | Condition |
|---|---|
| ArgumentNullException | propertyName is null. |
| InvalidOperationException | The current YamlNode is not a YamlObject. |
MethodsLink to this heading
AsArrayLink to this heading
Casts to the derived YamlArray type.
public YamlArray AsArray();
Returns: A YamlArray.
| Exception | Condition |
|---|---|
| InvalidOperationException | The node is not a YamlArray. |
AsObjectLink to this heading
Casts to the derived YamlObject type.
public YamlObject AsObject();
Returns: A YamlObject.
| Exception | Condition |
|---|---|
| InvalidOperationException | The node is not a YamlObject. |
AsValueLink to this heading
Casts to the derived YamlValue type.
public YamlValue AsValue();
Returns: A YamlValue.
| Exception | Condition |
|---|---|
| InvalidOperationException | The node is not a YamlValue. |
DeepCloneLink to this heading
Creates a new instance of the YamlNode. All children nodes are recursively cloned.
public YamlNode DeepClone();
Returns: A new cloned instance of the current node.
DeepEqualsLink to this heading
Compares the values of two nodes, including the values of all descendant nodes.
public static bool DeepEquals(YamlNode? node1, YamlNode? node2);
Parameters
Returns: true if the tokens are equal; otherwise false.
GetElementIndexLink to this heading
Returns index of the current node from the parent YamlArray.
public int GetElementIndex();
| Exception | Condition |
|---|---|
| InvalidOperationException | The current parent is not a YamlArray. |
GetPathLink to this heading
Gets the YAML path.
public string GetPath();
Returns: The JSON Path value.
GetPropertyNameLink to this heading
Returns property name of the current node from the parent object.
public string GetPropertyName();
| Exception | Condition |
|---|---|
| InvalidOperationException | The current parent is not a YamlObject. |
GetValueLink to this heading
Gets the value for the current YamlValue.
public virtual T? GetValue<T>();
Type parameters
T: The type of the value to obtain from theYamlValue.
Returns: A value converted from the YamlValue instance.
| Exception | Condition |
|---|---|
| FormatException | The current YamlNode cannot be represented as a . |
| InvalidOperationException | The current YamlNode is not a YamlValue or is not compatible with . |
can be the type or base type of the underlying value. If the underlying value is a YamlElement then can also be the type of any primitive value supported by current YamlElement. Specifying the Object type for will always succeed and return the underlying value as Object.
The underlying value of a YamlValue after deserialization is an instance of YamlElement, otherwise it's the value specified when the YamlValue was created.
GetValueKindLink to this heading
Returns YamlValueKind of current instance.
public YamlValueKind GetValueKind();
ParseLink to this heading
Parses one YAML value (including objects or arrays) from the provided reader.
public static YamlNode? Parse(ref Utf8YamlReader reader, YamlNodeOptions? nodeOptions = null);
Parameters
reader: The reader to read.nodeOptions: Options to control the behavior.
Returns: The YamlNode from the reader.
| Exception | Condition |
|---|---|
| ArgumentException | reader is using unsupported options. |
| ArgumentException | The current reader token does not start or represent a value. |
| YamlException | A value could not be read from the reader. |
If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.
Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.
This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
Parses text representing a single YAML value.
public static YamlNode? Parse(string yaml, YamlNodeOptions? nodeOptions = null, YamlDocumentOptions documentOptions = default);
Parameters
yaml: YAML text to parse.nodeOptions: Options to control the node behavior after parsing.documentOptions: Options to control the document behavior during parsing.
Returns: A YamlNode representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml is null. |
| YamlException | yaml does not represent a valid single YAML value. |
Parses text representing a single YAML value.
public static YamlNode? Parse(ReadOnlySpan<byte> utf8Yaml, YamlNodeOptions? nodeOptions = null, YamlDocumentOptions documentOptions = default);
Parameters
utf8Yaml: YAML text to parse.nodeOptions: Options to control the node behavior after parsing.documentOptions: Options to control the document behavior during parsing.
Returns: A YamlNode representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | utf8Yaml does not represent a valid single YAML value. |
Parse a Stream as UTF-8 encoded data representing a single YAML value into a YamlNode. The Stream will be read to completion.
public static YamlNode? Parse(Stream utf8Yaml, YamlNodeOptions? nodeOptions = null, YamlDocumentOptions documentOptions = default);
Parameters
utf8Yaml: YAML text to parse.nodeOptions: Options to control the node behavior after parsing.documentOptions: Options to control the document behavior during parsing.
Returns: A YamlNode representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | utf8Yaml does not represent a valid single YAML value. |
ParseAsyncLink to this heading
Parse a Stream as UTF-8 encoded data representing a single YAML value into a YamlNode. The Stream will be read to completion.
public static Task<YamlNode?> ParseAsync(Stream utf8Yaml, YamlNodeOptions? nodeOptions = null, YamlDocumentOptions documentOptions = default, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML text to parse.nodeOptions: Options to control the node behavior after parsing.documentOptions: Options to control the document behavior during parsing.cancellationToken: The token to monitor for cancellation requests.
Returns: A Task to produce a YamlNode representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | utf8Yaml does not represent a valid single YAML value. |
ReplaceWithLink to this heading
Replaces this node with a new value.
public void ReplaceWith<T>(T? value);
Type parameters
T: The type of value to be replaced.
Parameters
value: Value that replaces this node.
ToStringLink to this heading
Gets a string representation for the current value appropriate to the node type.
public override string ToString();
Returns: A string representation for the current value appropriate to the node type.
ToYamlStringLink to this heading
Converts the current instance to a string in YAML, in the style the options give.
public string ToYamlString(YamlSerializerOptions? options = null);
Parameters
options: Options to control the serialization behavior.
Returns: YAML representation of current instance.
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 YamlSerializerOptions.IgnoreSourceStyles is set, which writes in the options' styles.
WriteToLink to this heading
Write the YamlNode into the provided Utf8YamlWriter as YAML.
public abstract 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.
OperatorsLink to this heading
Explicit operatorLink to this heading
Defines an explicit conversion of a given Boolean to a YamlNode.
public static explicit operator bool(YamlNode value);
Parameters
value: ABooleanto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Boolean to a YamlNode.
public static explicit operator bool?(YamlNode? value);
Parameters
value: ABooleanto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Byte to a YamlNode.
public static explicit operator byte(YamlNode value);
Parameters
value: AByteto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Byte to a YamlNode.
public static explicit operator byte?(YamlNode? value);
Parameters
value: AByteto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Char to a YamlNode.
public static explicit operator char(YamlNode value);
Parameters
value: ACharto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Char to a YamlNode.
public static explicit operator char?(YamlNode? value);
Parameters
value: ACharto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given DateTime to a YamlNode.
public static explicit operator DateTime(YamlNode value);
Parameters
value: ADateTimeto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given DateTime to a YamlNode.
public static explicit operator DateTime?(YamlNode? value);
Parameters
value: ADateTimeto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given DateTimeOffset to a YamlNode.
public static explicit operator DateTimeOffset(YamlNode value);
Parameters
value: ADateTimeOffsetto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given DateTimeOffset to a YamlNode.
public static explicit operator DateTimeOffset?(YamlNode? value);
Parameters
value: ADateTimeOffsetto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Decimal to a YamlNode.
public static explicit operator decimal(YamlNode value);
Parameters
value: ADecimalto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Decimal to a YamlNode.
public static explicit operator decimal?(YamlNode? value);
Parameters
value: ADecimalto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Double to a YamlNode.
public static explicit operator double(YamlNode value);
Parameters
value: ADoubleto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Double to a YamlNode.
public static explicit operator double?(YamlNode? value);
Parameters
value: ADoubleto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Guid to a YamlNode.
public static explicit operator Guid(YamlNode value);
Parameters
value: AGuidto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Guid to a YamlNode.
public static explicit operator Guid?(YamlNode? value);
Parameters
value: AGuidto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Int16 to a YamlNode.
public static explicit operator short(YamlNode value);
Parameters
value: AInt16to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Int16 to a YamlNode.
public static explicit operator short?(YamlNode? value);
Parameters
value: AInt16to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Int32 to a YamlNode.
public static explicit operator int(YamlNode value);
Parameters
value: AInt32to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Int32 to a YamlNode.
public static explicit operator int?(YamlNode? value);
Parameters
value: AInt32to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Int64 to a YamlNode.
public static explicit operator long(YamlNode value);
Parameters
value: AInt64to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Int64 to a YamlNode.
public static explicit operator long?(YamlNode? value);
Parameters
value: AInt64to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given SByte to a YamlNode.
public static explicit operator sbyte(YamlNode value);
Parameters
value: ASByteto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given SByte to a YamlNode.
public static explicit operator sbyte?(YamlNode? value);
Parameters
value: ASByteto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Single to a YamlNode.
public static explicit operator float(YamlNode value);
Parameters
value: ASingleto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given Single to a YamlNode.
public static explicit operator float?(YamlNode? value);
Parameters
value: ASingleto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given String to a YamlNode.
public static explicit operator string?(YamlNode? value);
Parameters
value: AStringto explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given UInt16 to a YamlNode.
public static explicit operator ushort(YamlNode value);
Parameters
value: AUInt16to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given UInt16 to a YamlNode.
public static explicit operator ushort?(YamlNode? value);
Parameters
value: AUInt16to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given UInt32 to a YamlNode.
public static explicit operator uint(YamlNode value);
Parameters
value: AUInt32to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given UInt32 to a YamlNode.
public static explicit operator uint?(YamlNode? value);
Parameters
value: AUInt32to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given UInt64 to a YamlNode.
public static explicit operator ulong(YamlNode value);
Parameters
value: AUInt64to explicitly convert.
Returns: A value converted from the YamlNode instance.
Defines an explicit conversion of a given UInt64 to a YamlNode.
public static explicit operator ulong?(YamlNode? value);
Parameters
value: AUInt64to explicitly convert.
Returns: A value converted from the YamlNode instance.
Implicit operatorLink to this heading
Defines an implicit conversion of a given Boolean to a YamlNode.
public static implicit operator YamlNode(bool value);
Parameters
value: ABooleanto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Boolean to a YamlNode.
public static implicit operator YamlNode?(bool? value);
Parameters
value: ABooleanto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Byte to a YamlNode.
public static implicit operator YamlNode(byte value);
Parameters
value: AByteto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Byte to a YamlNode.
public static implicit operator YamlNode?(byte? value);
Parameters
value: AByteto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Char to a YamlNode.
public static implicit operator YamlNode(char value);
Parameters
value: ACharto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Char to a YamlNode.
public static implicit operator YamlNode?(char? value);
Parameters
value: ACharto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given DateTime to a YamlNode.
public static implicit operator YamlNode(DateTime value);
Parameters
value: ADateTimeto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given DateTime to a YamlNode.
public static implicit operator YamlNode?(DateTime? value);
Parameters
value: ADateTimeto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given DateTimeOffset to a YamlNode.
public static implicit operator YamlNode(DateTimeOffset value);
Parameters
value: ADateTimeOffsetto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given DateTimeOffset to a YamlNode.
public static implicit operator YamlNode?(DateTimeOffset? value);
Parameters
value: ADateTimeOffsetto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Decimal to a YamlNode.
public static implicit operator YamlNode(decimal value);
Parameters
value: ADecimalto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Decimal to a YamlNode.
public static implicit operator YamlNode?(decimal? value);
Parameters
value: ADecimalto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Double to a YamlNode.
public static implicit operator YamlNode(double value);
Parameters
value: ADoubleto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Double to a YamlNode.
public static implicit operator YamlNode?(double? value);
Parameters
value: ADoubleto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Guid to a YamlNode.
public static implicit operator YamlNode(Guid value);
Parameters
value: AGuidto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Guid to a YamlNode.
public static implicit operator YamlNode?(Guid? value);
Parameters
value: AGuidto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Int16 to a YamlNode.
public static implicit operator YamlNode(short value);
Parameters
value: AInt16to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Int16 to a YamlNode.
public static implicit operator YamlNode?(short? value);
Parameters
value: AInt16to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Int32 to a YamlNode.
public static implicit operator YamlNode(int value);
Parameters
value: AInt32to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Int32 to a YamlNode.
public static implicit operator YamlNode?(int? value);
Parameters
value: AInt32to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Int64 to a YamlNode.
public static implicit operator YamlNode(long value);
Parameters
value: AInt64to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Int64 to a YamlNode.
public static implicit operator YamlNode?(long? value);
Parameters
value: AInt64to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given SByte to a YamlNode.
public static implicit operator YamlNode(sbyte value);
Parameters
value: ASByteto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given SByte to a YamlNode.
public static implicit operator YamlNode?(sbyte? value);
Parameters
value: ASByteto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Single to a YamlNode.
public static implicit operator YamlNode(float value);
Parameters
value: ASingleto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given Single to a YamlNode.
public static implicit operator YamlNode?(float? value);
Parameters
value: ASingleto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given String to a YamlNode.
public static implicit operator YamlNode?(string? value);
Parameters
value: AStringto implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given UInt16 to a YamlNode.
public static implicit operator YamlNode(ushort value);
Parameters
value: AUInt16to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given UInt16 to a YamlNode.
public static implicit operator YamlNode?(ushort? value);
Parameters
value: AUInt16to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given UInt32 to a YamlNode.
public static implicit operator YamlNode(uint value);
Parameters
value: AUInt32to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given UInt32 to a YamlNode.
public static implicit operator YamlNode?(uint? value);
Parameters
value: AUInt32to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given UInt64 to a YamlNode.
public static implicit operator YamlNode(ulong value);
Parameters
value: AUInt64to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.
Defines an implicit conversion of a given UInt64 to a YamlNode.
public static implicit operator YamlNode?(ulong? value);
Parameters
value: AUInt64to implicitly convert.
Returns: A YamlNode instance converted from the value parameter.