YamlElement Struct
A node of a YamlDocument: a scalar, a mapping, a sequence or an alias.
public readonly struct YamlElement : IEquatable<YamlElement>- Implements
Nested types
| Name | Description |
|---|---|
| YamlElement.MappingEnumerator | Enumerates the entries of a mapping. |
| YamlElement.SequenceEnumerator | Enumerates the items of a sequence. |
Properties
| Name | Description |
|---|---|
| Anchor | Gets the anchor of the node, or the name an alias refers to. |
| End | Gets the location of the end of the node, after its content. |
| IsFlow | Gets a value indicating whether the collection is written in the flow style. |
| IsNull | Gets a value indicating whether the node is a null of the core schema: an empty plain scalar, ~ or null, without tag. |
| Kind | Gets the kind of the node. |
| ScalarStyle | Gets the style of the scalar. |
| Start | Gets the location of the start of the node, at its anchor or tag if any. |
| Tag | Gets the tag of the node resolved with the %TAG directives, such as tag:yaml.org,2002:str. |
| Utf8Length | Gets the length of the text of the node in YamlDocument.Utf8Text, in bytes, with its properties and its content. |
| Utf8Offset | Gets the offset of the node in YamlDocument.Utf8Text, in bytes, at its anchor or tag if any. |
Anchor
YamlElement.csGets the location of the end of the node, after its content.
public Mark End { get; }IsFlow
YamlElement.csIsNull
YamlElement.csKind
YamlElement.csScalarStyle
YamlElement.csStart
YamlElement.csGets the location of the start of the node, at its anchor or tag if any.
public Mark Start { get; }Property value
Remarks
Mark.Index counts UTF-16 characters: it is the index in the string the document was parsed from, or in the decoded text of UTF-8 input. Line and column are 0-based.
Utf8Length
YamlElement.csGets the length of the text of the node in YamlDocument.Utf8Text, in bytes, with its properties and its content.
public int Utf8Length { get; }Property value
Utf8Offset
YamlElement.csGets the offset of the node in YamlDocument.Utf8Text, in bytes, at its anchor or tag if any.
public int Utf8Offset { get; }Property value
Remarks
The offset counts UTF-8 bytes, even when the document was parsed from a string. Use YamlElement.Start for a position in the string. The offset of a node of a YamlElement.Clone is the offset in the input of the original.
Indexers
| Name | Description |
|---|---|
| this[int] | Gets the item of a sequence. |
| this[string] | Gets the value of a mapping entry whose key is the scalar key. |
Item overloads
this[int]
YamlElement.csGets the item of a sequence.
public YamlElement this[int index] { get; }Parameters
indexint
Property value
Exceptions
InvalidOperationException- The node is not a sequence.
ArgumentOutOfRangeExceptionindexis outside the sequence.
this[string]
YamlElement.csGets the value of a mapping entry whose key is the scalar key.
public YamlElement this[string key] { get; }Methods
| Name | Description |
|---|---|
| Clone() | Gets a copy of the node that stays valid after its document is disposed, like JsonElement.Clone in System.Text.Json. |
| EnumerateMapping() | Enumerates the entries of a mapping. |
| EnumerateSequence() | Enumerates the items of a sequence. |
| Equals(YamlElement) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| GetHashCode() | Returns the hash code for this instance. |
| GetLength() | Gets the number of items of a sequence, or of entries of a mapping. |
| GetRawText() | Gets the text of the node in the input, with its properties and its content. |
| GetRawUtf8Text() | Gets the text of the node in the input, byte for byte, without allocating. |
| GetString() | Decodes the value of the scalar. |
| ResolveAlias() | Gets the node an alias refers to: the last node before it with that anchor, in the same document. |
| ToString() | Returns the value of a scalar, or the text of a collection. |
| TryGetBoolean(bool) | Parses the plain scalar as a boolean of the core schema: true, True, TRUE, false, False, FALSE. |
| TryGetDouble(double) | Parses the plain scalar as a floating-point number, including .inf, -.inf and .nan. |
| TryGetInt64(long) | Parses the plain scalar as a 64-bit integer, in the decimal notation. |
| TryGetProperty(ReadOnlySpan<byte>, YamlElement) | Finds the value of a mapping entry whose key is a scalar equal to a UTF-8 text, without allocating. |
| TryGetProperty(ReadOnlySpan<char>, YamlElement) | Finds the value of a mapping entry whose key is a scalar equal to key, without allocating. |
| TryGetProperty(string, YamlElement) | Finds the value of a mapping entry whose key is a scalar equal to key. |
| ValueEquals(ReadOnlySpan<byte>) | Compares the value of the scalar with a UTF-8 text without allocating. |
| ValueEquals(ReadOnlySpan<char>) | Compares the value of the scalar with a text without allocating. |
| ValueEquals(string) | Compares the value of the scalar with a text without allocating. |
| WriteTo(Utf8YamlWriter) | Writes the node and its descendants: their values, styles, anchors and tags. |
Clone()
YamlElement.csGets a copy of the node that stays valid after its document is disposed, like JsonElement.Clone in System.Text.Json.
public YamlElement Clone()Returns
YamlElement The node in a document of its own, which owns its memory and does not need to be disposed.
Exceptions
ObjectDisposedException- The document of the node is disposed.
Remarks
The copy holds the text of the lines of the node and of its descendants, not the whole input. It has the same values, text, anchors and tags, and the same positions in the input: YamlElement.Start, YamlElement.End and YamlElement.Utf8Offset. An alias of the node still resolves to the node of its anchor: the anchored nodes that are not in the node are copied too.
A node of a copy is returned as is. A copy is another node: it is not equal to the original.
EnumerateMapping()
YamlElement.csEnumerates the entries of a mapping.
public YamlElement.MappingEnumerator EnumerateMapping()EnumerateSequence()
YamlElement.csEnumerates the items of a sequence.
public YamlElement.SequenceEnumerator EnumerateSequence()Equals overloads
Equals(YamlElement)
YamlElement.csIndicates whether the current object is equal to another object of the same type.
public bool Equals(YamlElement other)Parameters
otherYamlElement- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
YamlElement.csGetHashCode()
YamlElement.csGetLength()
YamlElement.csGets the number of items of a sequence, or of entries of a mapping.
public int GetLength()GetRawText()
YamlElement.csGetRawUtf8Text()
YamlElement.csGets the text of the node in the input, byte for byte, without allocating.
public ReadOnlySpan<byte> GetRawUtf8Text()Returns
GetString()
YamlElement.csDecodes the value of the scalar.
public string GetString()ResolveAlias()
YamlElement.csGets the node an alias refers to: the last node before it with that anchor, in the same document.
public YamlElement ResolveAlias()ToString()
YamlElement.csTryGetBoolean(bool)
YamlElement.csTryGetDouble(double)
YamlElement.csTryGetInt64(long)
YamlElement.csTryGetProperty overloads
TryGetProperty(ReadOnlySpan<byte>, YamlElement)
YamlElement.csFinds the value of a mapping entry whose key is a scalar equal to a UTF-8 text, without allocating.
public bool TryGetProperty(ReadOnlySpan<byte> utf8Key, out YamlElement value)TryGetProperty(ReadOnlySpan<char>, YamlElement)
YamlElement.csFinds the value of a mapping entry whose key is a scalar equal to key, without allocating.
public bool TryGetProperty(ReadOnlySpan<char> key, out YamlElement value)TryGetProperty(string, YamlElement)
YamlElement.csFinds the value of a mapping entry whose key is a scalar equal to key.
public bool TryGetProperty(string key, out YamlElement value)ValueEquals overloads
ValueEquals(ReadOnlySpan<byte>)
YamlElement.csCompares the value of the scalar with a UTF-8 text without allocating.
public bool ValueEquals(ReadOnlySpan<byte> utf8Text)ValueEquals(ReadOnlySpan<char>)
YamlElement.csCompares the value of the scalar with a text without allocating.
public bool ValueEquals(ReadOnlySpan<char> text)Parameters
textReadOnlySpan<char>
Returns
Remarks
A text with an invalid UTF-16 sequence, such as a lone surrogate, is equal to no value.
ValueEquals(string)
YamlElement.csCompares the value of the scalar with a text without allocating.
WriteTo(Utf8YamlWriter)
YamlElement.csWrites the node and its descendants: their values, styles, anchors and tags.
public void WriteTo(Utf8YamlWriter writer)Parameters
writerUtf8YamlWriter- The destination.
Exceptions
ArgumentNullExceptionwriterisnull.ArgumentException- A tag is neither
!, a local tag nor a URI, and the writer has no%TAGdirective whose prefix starts it: seeUtf8YamlWriter.WriteTagDirective.YamlDocument.WriteTowrites the directives of the documents.
Remarks
A plain scalar stays plain, so it keeps its type. A quoted or block scalar may be written in another quoted style, and a folded scalar is written as a literal one. Comments and document markers are not written.
Operators
| Name | Description |
|---|---|
| operator ==(YamlElement, YamlElement) | |
| operator !=(YamlElement, YamlElement) |
operator ==(YamlElement, YamlElement)
YamlElement.cspublic static bool operator ==(YamlElement left, YamlElement right)No documentation is available.
operator !=(YamlElement, YamlElement)
YamlElement.cspublic static bool operator !=(YamlElement left, YamlElement right)No documentation is available.