YamlElement struct
Represents a specific YAML value within a YamlDocument.
Namespace: System.Text.Yaml · Assembly: Styml.dll
public readonly struct YamlElement
Represents a specific YAML value within a YamlDocument.
PropertiesLink to this heading
CollectionStyleLink to this heading
Gets the source style of this collection: YamlCollectionStyle.Flow for […] or {…} (JSON's collections among them) and for a single-pair mapping in a flow sequence ([a: b]), YamlCollectionStyle.Block otherwise; null when this element is not an object or an array. An alias gives its anchored node's, as YamlElement.ValueKind does. Writing the element back with a block-style writer keeps it, unless YamlWriterOptions.IgnoreSourceStyles is set.
public YamlCollectionStyle? CollectionStyle { get; }
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
IsAliasLink to this heading
Gets a value that indicates whether this element was reached through an alias (*name). Such an element is the anchored node: its kind, value and children are that node's.
public bool IsAlias { get; }
ScalarStyleLink to this heading
Gets the style the scalar was written in, or YamlScalarStyle.None for a mapping or a sequence.
public YamlScalarStyle ScalarStyle { get; }
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
ValueKindLink to this heading
The YamlValueKind that the value is.
public YamlValueKind ValueKind { get; }
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
this[]Link to this heading
Get the value at a specified index when the current value is a YamlValueKind.Array.
public YamlElement this[int index] { get; }
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Array. |
| IndexOutOfRangeException | index is not in the range [0, YamlElement.GetArrayLength()). |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
MethodsLink to this heading
CloneLink to this heading
Get a YamlElement which can be safely stored beyond the lifetime of the original YamlDocument.
public YamlElement Clone();
Returns: A YamlElement which can be safely stored beyond the lifetime of the original YamlDocument.
If this YamlElement is itself the output of a previous call to Clone, or a value contained within another YamlElement which was the output of a previous call to Clone, this method results in no additional memory allocation.
DeepEqualsLink to this heading
Compares the values of two YamlElement values for equality, including the values of all descendant elements.
public static bool DeepEquals(YamlElement element1, YamlElement element2);
Parameters
element1: The firstYamlElementto compare.element2: The secondYamlElementto compare.
Returns: true if the two values are equal; otherwise, false.
Deep equality of two YAML values is defined as follows:
- YAML values of different kinds are not equal.
- YAML constants
null,false, andtrueonly equal themselves. - YAML numbers are equal if and only if they have they have equivalent decimal representations, with no rounding being used.
- YAML strings are equal if and only if they are equal using ordinal string comparison.
- YAML arrays are equal if and only if they are of equal length and each of their elements are pairwise equal.
- YAML objects are equal if and only if they have the same number of properties and each property in the first object has a corresponding property in the second object with the same name and equal value. The order of properties is not significant, with the exception of repeated properties that must be specified in the same order (with interleaving allowed).
- YAML (M5a): an alias compares as the node it refers to, and an alias inside the node it refers to compares as equal where both sides repeat alike. Anchors, tags and scalar styles are not compared: equality is of values, as for YAML. A tag that changes a value's kind shows through
YamlElement.ValueKind. Numbers in a YAML spelling (0x1F,.inf) compare by their value.
A document with aliases is compared with a bound on depth (the document's YamlDocumentOptions.MaxDepth, counted across aliases), past which a YamlException is thrown.
EnumerateArrayLink to this heading
Get an enumerator to enumerate the values in the YAML array represented by this YamlElement.
public YamlElement.ArrayEnumerator EnumerateArray();
Returns: An enumerator to enumerate the values in the YAML array represented by this YamlElement.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Array. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
EnumerateObjectLink to this heading
Get an enumerator to enumerate the properties in the YAML object represented by this YamlElement.
public YamlElement.ObjectEnumerator EnumerateObject();
Returns: An enumerator to enumerate the properties in the YAML object represented by this YamlElement.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetAnchorLink to this heading
Gets the anchor of this node (&name), without the &, or null when it has none.
public string? GetAnchor();
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
An element reached through an alias (YamlElement.IsAlias) is the anchored node, so it returns that node's anchor.
GetArrayLengthLink to this heading
Get the number of values contained within the current array value.
public int GetArrayLength();
Returns: The number of values contained within the current array value.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Array. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetBooleanLink to this heading
Gets the value of the element as a Boolean.
public bool GetBoolean();
Returns: The value of the element as a Boolean.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is neither YamlValueKind.True or YamlValueKind.False. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
GetByteLink to this heading
Gets the current YAML number as a Byte.
public byte GetByte();
Returns: The current YAML number as a Byte.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a Byte. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
GetBytesFromBase64Link to this heading
Gets the value of the element as bytes.
public byte[] GetBytesFromBase64();
Returns: The value decode to bytes.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| FormatException | The value is not encoded as Base64 text and hence cannot be decoded to bytes. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a byte[] representation of values other than Base64 encoded YAML strings.
GetDateTimeLink to this heading
Gets the value of the element as a DateTime.
public DateTime GetDateTime();
Returns: The value of the element as a DateTime.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| FormatException | The value cannot be represented as a DateTime. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a DateTime representation of values other than YAML strings.
GetDateTimeOffsetLink to this heading
Gets the value of the element as a DateTimeOffset.
public DateTimeOffset GetDateTimeOffset();
Returns: The value of the element as a DateTimeOffset.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| FormatException | The value cannot be represented as a DateTimeOffset. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a DateTimeOffset representation of values other than YAML strings.
GetDecimalLink to this heading
Gets the current YAML number as a Decimal.
public decimal GetDecimal();
Returns: The current YAML number as a Decimal.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a Decimal. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
GetDoubleLink to this heading
Gets the current YAML number as a Double.
public double GetDouble();
Returns: The current YAML number as a Double.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a Double. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
On .NET Core this method returns Double.PositiveInfinity (or Double.NegativeInfinity) for values larger than Double.MaxValue (or smaller than Double.MinValue).
GetExpandedTagLink to this heading
Gets the tag of this node with its handle expanded by the document's %TAG directives and the standard handles (!!str is tag:yaml.org,2002:str), or null when it has none.
public string? GetExpandedTag();
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetGuidLink to this heading
Gets the value of the element as a Guid.
public Guid GetGuid();
Returns: The value of the element as a Guid.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| FormatException | The value cannot be represented as a Guid. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a Guid representation of values other than YAML strings.
GetInt16Link to this heading
Gets the current YAML number as an Int16.
public short GetInt16();
Returns: The current YAML number as an Int16.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as an Int16. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetInt32Link to this heading
Gets the current YAML number as an Int32.
public int GetInt32();
Returns: The current YAML number as an Int32.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as an Int32. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetInt64Link to this heading
Gets the current YAML number as a Int64.
public long GetInt64();
Returns: The current YAML number as a Int64.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a Int64. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
GetPropertyLink to this heading
Gets a YamlElement representing the value of a required property identified by propertyName.
public YamlElement GetProperty(string propertyName);
Parameters
propertyName: Name of the property whose value to return.
Returns: A YamlElement representing the value of the requested property.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| KeyNotFoundException | No property was found with the requested name. |
| ArgumentNullException | propertyName is null. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
Property name matching is performed as an ordinal, case-sensitive, comparison. If a property is defined multiple times for the same object, the last such definition is what is matched.
Gets a YamlElement representing the value of a required property identified by propertyName.
public YamlElement GetProperty(ReadOnlySpan<char> propertyName);
Parameters
propertyName: Name of the property whose value to return.
Returns: A YamlElement representing the value of the requested property.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| KeyNotFoundException | No property was found with the requested name. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
Property name matching is performed as an ordinal, case-sensitive, comparison.
If a property is defined multiple times for the same object, the last such definition is what is matched.
Gets a YamlElement representing the value of a required property identified by utf8PropertyName.
public YamlElement GetProperty(ReadOnlySpan<byte> utf8PropertyName);
Parameters
utf8PropertyName: The UTF-8 (with no Byte-Order-Mark (BOM)) representation of the name of the property to return.
Returns: A YamlElement representing the value of the requested property.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| KeyNotFoundException | No property was found with the requested name. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
Property name matching is performed as an ordinal, case-sensitive, comparison.
If a property is defined multiple times for the same object, the last such definition is what is matched.
GetPropertyCountLink to this heading
Get the number of properties contained within the current object value.
public int GetPropertyCount();
Returns: The number of properties contained within the current object value.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetRawTextLink to this heading
Gets the original input data backing this value, returning it as a String.
public string GetRawText();
Returns: The original input data backing this value, returning it as a String.
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
For YAML the text stands alone: YamlDocument.Parse reads it back to an equal value. A nested block collection's continuation lines lose the node's indentation, a flow-sequence pair ([a: b]) is given its braces, the node's tag is kept in front, and a block scalar's indentation indicator keeps its meaning. Three texts do not stand alone: a node with an alias whose anchor is outside the node, a node whose tag needs a %TAG directive of its stream, and an empty node, whose text is empty (which YamlDocument.Parse refuses). The source bytes, unchanged, are YamlMarshal.GetRawUtf8Value.
GetSByteLink to this heading
Gets the current YAML number as an SByte.
public sbyte GetSByte();
Returns: The current YAML number as an SByte.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as an SByte. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetSingleLink to this heading
Gets the current YAML number as a Single.
public float GetSingle();
Returns: The current YAML number as a Single.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a Single. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
On .NET Core this method returns Single.PositiveInfinity (or Single.NegativeInfinity) for values larger than Single.MaxValue (or smaller than Single.MinValue).
GetStringLink to this heading
Gets the value of the element as a String.
public string? GetString();
Returns: The value of the element as a String.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is neither YamlValueKind.String nor YamlValueKind.Null. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a string representation of values other than YAML strings.
GetTagLink to this heading
Gets the tag of this node as written (!local, !!str, !<uri>), or null when it has none.
public string? GetTag();
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
GetUInt16Link to this heading
Gets the current YAML number as a UInt16.
public ushort GetUInt16();
Returns: The current YAML number as a UInt16.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a UInt16. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
GetUInt32Link to this heading
Gets the current YAML number as a UInt32.
public uint GetUInt32();
Returns: The current YAML number as a UInt32.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a UInt32. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
GetUInt64Link to this heading
Gets the current YAML number as a UInt64.
public ulong GetUInt64();
Returns: The current YAML number as a UInt64.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| FormatException | The value cannot be represented as a UInt64. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
ParseLink to this heading
Parses UTF8-encoded text representing a single YAML value into a YamlElement.
public static YamlElement Parse(ReadOnlySpan<byte> utf8Yaml, YamlDocumentOptions options = default);
Parameters
utf8Yaml: The YAML text to parse.options: Options to control the reader behavior during parsing.
Returns: A YamlElement representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | utf8Yaml does not represent a valid single YAML value. |
| ArgumentException | options contains unsupported options. |
Parses text representing a single YAML value into a YamlElement.
public static YamlElement Parse(ReadOnlySpan<char> yaml, YamlDocumentOptions options = default);
Parameters
yaml: The YAML text to parse.options: Options to control the reader behavior during parsing.
Returns: A YamlElement representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | yaml does not represent a valid single YAML value. |
| ArgumentException | options contains unsupported options. |
Parses text representing a single YAML value into a YamlElement.
public static YamlElement Parse(string yaml, YamlDocumentOptions options = default);
Parameters
yaml: The YAML text to parse.options: Options to control the reader behavior during parsing.
Returns: A YamlElement representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml is null. |
| YamlException | yaml does not represent a valid single YAML value. |
| ArgumentException | options contains unsupported options. |
ParseValueLink to this heading
Parses one YAML value (including objects or arrays) from the provided reader.
public static YamlElement ParseValue(ref Utf8YamlReader reader);
Parameters
reader: The reader to read.
Returns: A YamlElement representing the value (and nested values) read 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.
ToStringLink to this heading
Gets a string representation for the current value appropriate to the value type.
public override string ToString();
Returns: A string representation for the current value appropriate to the value type.
| Exception | Condition |
|---|---|
| ObjectDisposedException | The parent YamlDocument has been disposed. |
For YamlElement built from YamlDocument:
For YamlValueKind.Null, String.Empty is returned.
For YamlValueKind.True, Boolean.TrueString is returned.
For YamlValueKind.False, Boolean.FalseString is returned.
For YamlValueKind.String, the value of YamlElement.GetString() is returned.
For other types, the value of YamlElement.GetRawText() is returned.
TryGetByteLink to this heading
Attempts to represent the current YAML number as a Byte.
public bool TryGetByte(out byte value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a Byte, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetBytesFromBase64Link to this heading
Attempts to represent the current YAML string as bytes assuming it is Base64 encoded.
public bool TryGetBytesFromBase64(out byte[]? value);
Parameters
value: Receives the value.
Returns: true if the entire token value is encoded as valid Base64 text and can be successfully decoded to bytes. false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a byte[] representation of values other than base 64 encoded YAML strings.
TryGetDateTimeLink to this heading
Attempts to represent the current YAML string as a DateTime.
public bool TryGetDateTime(out DateTime value);
Parameters
value: Receives the value.
Returns: true if the string can be represented as a DateTime, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a DateTime representation of values other than YAML strings.
TryGetDateTimeOffsetLink to this heading
Attempts to represent the current YAML string as a DateTimeOffset.
public bool TryGetDateTimeOffset(out DateTimeOffset value);
Parameters
value: Receives the value.
Returns: true if the string can be represented as a DateTimeOffset, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a DateTimeOffset representation of values other than YAML strings.
TryGetDecimalLink to this heading
Attempts to represent the current YAML number as a Decimal.
public bool TryGetDecimal(out decimal value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a Decimal, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetDoubleLink to this heading
Attempts to represent the current YAML number as a Double.
public bool TryGetDouble(out double value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a Double, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
On .NET Core this method does not return false for values larger than Double.MaxValue (or smaller than Double.MinValue), instead true is returned and Double.PositiveInfinity (or Double.NegativeInfinity) is emitted.
TryGetGuidLink to this heading
Attempts to represent the current YAML string as a Guid.
public bool TryGetGuid(out Guid value);
Parameters
value: Receives the value.
Returns: true if the string can be represented as a Guid, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not create a Guid representation of values other than YAML strings.
TryGetInt16Link to this heading
Attempts to represent the current YAML number as an Int16.
public bool TryGetInt16(out short value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as an Int16, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetInt32Link to this heading
Attempts to represent the current YAML number as an Int32.
public bool TryGetInt32(out int value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as an Int32, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetInt64Link to this heading
Attempts to represent the current YAML number as a Int64.
public bool TryGetInt64(out long value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a Int64, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetPropertyLink to this heading
Looks for a property named propertyName in the current object, returning whether or not such a property existed. When the property exists value is assigned to the value of that property.
public bool TryGetProperty(string propertyName, out YamlElement value);
Parameters
propertyName: Name of the property to find.value: Receives the value of the located property.
Returns: true if the property was found, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| ArgumentNullException | propertyName is null. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
Property name matching is performed as an ordinal, case-sensitive, comparison.
If a property is defined multiple times for the same object, the last such definition is what is matched.
Looks for a property named propertyName in the current object, returning whether or not such a property existed. When the property exists value is assigned to the value of that property.
public bool TryGetProperty(ReadOnlySpan<char> propertyName, out YamlElement value);
Parameters
propertyName: Name of the property to find.value: Receives the value of the located property.
Returns: true if the property was found, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
Property name matching is performed as an ordinal, case-sensitive, comparison.
If a property is defined multiple times for the same object, the last such definition is what is matched.
Looks for a property named utf8PropertyName in the current object, returning whether or not such a property existed. When the property exists value is assigned to the value of that property.
public bool TryGetProperty(ReadOnlySpan<byte> utf8PropertyName, out YamlElement value);
Parameters
utf8PropertyName: The UTF-8 (with no Byte-Order-Mark (BOM)) representation of the name of the property to return.value: Receives the value of the located property.
Returns: true if the property was found, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Object. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
Property name matching is performed as an ordinal, case-sensitive, comparison.
If a property is defined multiple times for the same object, the last such definition is what is matched.
TryGetSByteLink to this heading
Attempts to represent the current YAML number as an SByte.
public bool TryGetSByte(out sbyte value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as an SByte, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetSingleLink to this heading
Attempts to represent the current YAML number as a Single.
public bool TryGetSingle(out float value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a Single, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
On .NET Core this method does not return false for values larger than Single.MaxValue (or smaller than Single.MinValue), instead true is returned and Single.PositiveInfinity (or Single.NegativeInfinity) is emitted.
TryGetUInt16Link to this heading
Attempts to represent the current YAML number as a UInt16.
public bool TryGetUInt16(out ushort value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a UInt16, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetUInt32Link to this heading
Attempts to represent the current YAML number as a UInt32.
public bool TryGetUInt32(out uint value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a UInt32, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryGetUInt64Link to this heading
Attempts to represent the current YAML number as a UInt64.
public bool TryGetUInt64(out ulong value);
Parameters
value: Receives the value.
Returns: true if the number can be represented as a UInt64, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.Number. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
This method does not parse the contents of a YAML string value.
TryParseValueLink to this heading
Attempts to parse one YAML value (including objects or arrays) from the provided reader.
public static bool TryParseValue(ref Utf8YamlReader reader, out YamlElement? element);
Parameters
reader: The reader to read.element: Receives the parsed element.
Returns: true if a value was read and parsed into a YamlElement; false if the reader ran out of data while parsing. All other situations result in an exception being thrown.
| 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, or false is returned, 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.
ValueEqualsLink to this heading
Compares text to the string value of this element.
public bool ValueEquals(string? text);
Parameters
text: The text to compare against.
Returns: true if the string value of this element matches text, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
This method is functionally equal to doing an ordinal comparison of text and the result of calling YamlElement.GetString, but avoids creating the string instance.
Compares the text represented by utf8Text to the string value of this element.
public bool ValueEquals(ReadOnlySpan<byte> utf8Text);
Parameters
utf8Text: The UTF-8 encoded text to compare against.
Returns: true if the string value of this element has the same UTF-8 encoding as utf8Text, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
This method is functionally equal to doing an ordinal comparison of the string produced by UTF-8 decoding utf8Text with the result of calling YamlElement.GetString, but avoids creating the string instances.
Compares text to the string value of this element.
public bool ValueEquals(ReadOnlySpan<char> text);
Parameters
text: The text to compare against.
Returns: true if the string value of this element matches text, false otherwise.
| Exception | Condition |
|---|---|
| InvalidOperationException | This value's YamlElement.ValueKind is not YamlValueKind.String. |
This method is functionally equal to doing an ordinal comparison of text and the result of calling YamlElement.GetString, but avoids creating the string instance.
WriteToLink to this heading
Write the element into the provided writer as a YAML value.
public void WriteTo(Utf8YamlWriter writer);
Parameters
writer: The writer.
| Exception | Condition |
|---|---|
| ArgumentNullException | The writer parameter is null. |
| InvalidOperationException | This value's YamlElement.ValueKind is YamlValueKind.Undefined. |
| ObjectDisposedException | The parent YamlDocument has been disposed. |
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.
Nested typesLink to this heading
| Type | Description |
|---|---|
| YamlElement.ArrayEnumerator | An enumerable and enumerator for the contents of a YAML array. |
| YamlElement.ObjectEnumerator | An enumerable and enumerator for the properties of a YAML object. |