Utf8YamlReader struct
Provides a high-performance API for forward-only, read-only access to the UTF-8 encoded YAML text. It processes the text sequentially with no caching and adheres strictly to the YAML 1.2 specification by default (https://tools.ietf.org/html/rfc8259). When it encounters invalid YAML, it throws a YamlException with basic error information like line number and byte position on the line. Since this type is a ref struct, it does not directly support async. However, it does provide support for reentrancy to read incomplete data, and continue reading once more data is presented. To be able to set max depth while reading OR allow skipping comments, create an instance of YamlReaderState and pass that in to the reader.
Namespace: System.Text.Yaml ยท Assembly: Styml.dll
[Obsolete("Types with embedded references are not supported in this version of your compiler.")]
public ref struct Utf8YamlReader
Provides a high-performance API for forward-only, read-only access to the UTF-8 encoded YAML text. It processes the text sequentially with no caching and adheres strictly to the YAML 1.2 specification by default (https://tools.ietf.org/html/rfc8259). When it encounters invalid YAML, it throws a YamlException with basic error information like line number and byte position on the line. Since this type is a ref struct, it does not directly support async. However, it does provide support for reentrancy to read incomplete data, and continue reading once more data is presented. To be able to set max depth while reading OR allow skipping comments, create an instance of YamlReaderState and pass that in to the reader.
ConstructorsLink to this heading
Constructs a new Utf8YamlReader instance.
public Utf8YamlReader(ReadOnlySpan<byte> yamlData, bool isFinalBlock, YamlReaderState state);
Parameters
yamlData: The ReadOnlySpan<byte> containing the UTF-8 encoded YAML text to process.isFinalBlock: True when the input span contains the entire data to process. Set to false only if it is known that the input span contains partial data with more data to follow.state: If this is the first call to the ctor, pass in a default state. Otherwise, capture the state from the previous instance of theUtf8YamlReaderand pass that back.
Since this type is a ref struct, it is a stack-only type and all the limitations of ref structs apply to it. This is the reason why the ctor accepts a YamlReaderState.
Constructs a new Utf8YamlReader instance.
public Utf8YamlReader(ReadOnlySpan<byte> yamlData, YamlReaderOptions options = default);
Parameters
yamlData: The ReadOnlySpan<byte> containing the UTF-8 encoded YAML text to process.options: Defines the customized behavior of theUtf8YamlReaderthat is different from the defaults (for example how to handle comments or maximum depth allowed when reading). By default, theUtf8YamlReaderfollows the YAML 1.2 specification and reads up to a maximum depth of 64.
Since this type is a ref struct, it is a stack-only type and all the limitations of ref structs apply to it.
This assumes that the entire YAML payload is passed in (equivalent to Utf8YamlReader.IsFinalBlock = true)
Constructs a new Utf8YamlReader instance.
public Utf8YamlReader(ReadOnlySequence<byte> yamlData, bool isFinalBlock, YamlReaderState state);
Parameters
yamlData: The ReadOnlySequence<byte> containing the UTF-8 encoded YAML text to process.isFinalBlock: True when the input span contains the entire data to process. Set to false only if it is known that the input span contains partial data with more data to follow.state: If this is the first call to the ctor, pass in a default state. Otherwise, capture the state from the previous instance of theUtf8YamlReaderand pass that back.
Since this type is a ref struct, it is a stack-only type and all the limitations of ref structs apply to it. This is the reason why the ctor accepts a YamlReaderState.
Constructs a new Utf8YamlReader instance.
public Utf8YamlReader(ReadOnlySequence<byte> yamlData, YamlReaderOptions options = default);
Parameters
yamlData: The ReadOnlySequence<byte> containing the UTF-8 encoded YAML text to process.options: Defines the customized behavior of theUtf8YamlReaderthat is different from the defaults (for example how to handle comments or maximum depth allowed when reading). By default, theUtf8YamlReaderfollows the YAML 1.2 specification and reads up to a maximum depth of 64.
Since this type is a ref struct, it is a stack-only type and all the limitations of ref structs apply to it.
This assumes that the entire YAML payload is passed in (equivalent to Utf8YamlReader.IsFinalBlock = true)
PropertiesLink to this heading
AnchorLink to this heading
Gets the anchor name (without '&') of the current node, or an empty span.
public ReadOnlySpan<byte> Anchor { get; }
BytesConsumedLink to this heading
Returns the total amount of bytes consumed by the Utf8YamlReader so far for the current instance of the Utf8YamlReader with the given UTF-8 encoded input text.
public long BytesConsumed { get; }
CurrentDepthLink to this heading
Tracks the recursive depth of the nested objects / arrays within the YAML text processed so far. This provides the depth of the current token.
public int CurrentDepth { get; }
CurrentStateLink to this heading
Returns the current snapshot of the Utf8YamlReader state which must be captured by the caller and passed back in to the Utf8YamlReader ctor with more data. Unlike the Utf8YamlReader, which is a ref struct, the state can survive across async/await boundaries and hence this type is required to provide support for reading in more data asynchronously before continuing with a new instance of the Utf8YamlReader.
public YamlReaderState CurrentState { get; }
HasValueSequenceLink to this heading
Lets the caller know which of the two 'Value' properties to read to get the token value. For input data within a ReadOnlySpan<byte> this will always return false. For input data within a ReadOnlySequence<byte>, this will only return true if the token value straddles more than a single segment and hence couldn't be represented as a span.
public bool HasValueSequence { get; }
IsFinalBlockLink to this heading
Returns the mode of this instance of the Utf8YamlReader. True when the reader was constructed with the input span containing the entire data to process. False when the reader was constructed knowing that the input span may contain partial data with more data to follow.
public bool IsFinalBlock { get; }
IsFlowLink to this heading
Gets whether the current collection token comes from a flow collection ({} or []).
public bool IsFlow { get; }
KeyKindLink to this heading
Gets what the current YamlTokenType.PropertyName token stands for: YamlKeyKind.Scalar for an ordinary key, YamlKeyKind.Alias for an alias key (*name : value, whose Utf8YamlReader.ValueSpan is the anchor name), YamlKeyKind.Complex for a collection used as a key ([a, b]: value, whose Utf8YamlReader.ValueSpan is the key's raw YAML), or YamlKeyKind.None when the current token is not a key. The string accessors refuse alias and complex keys.
public YamlKeyKind KeyKind { get; }
PositionLink to this heading
Returns the current SequencePosition within the provided UTF-8 encoded input ReadOnlySequence<byte>. If the Utf8YamlReader was constructed with a ReadOnlySpan<byte> instead, this will always return a default SequencePosition.
public SequencePosition Position { get; }
ScalarStyleLink to this heading
Gets the presentation style of the current scalar or mapping key token, or YamlScalarStyle.None for other tokens.
public YamlScalarStyle ScalarStyle { get; }
TagLink to this heading
Gets the tag of the current node as written in the input (for example !!str), or an empty span.
public ReadOnlySpan<byte> Tag { get; }
TokenStartIndexLink to this heading
Returns the index that the last processed YAML token starts at within the given UTF-8 encoded input text, skipping any white space.
public long TokenStartIndex { get; }
For YAML strings (including property names), this points to before the start quote. For comments, this points to before the first comment delimiter (i.e. '/').
TokenTypeLink to this heading
Gets the type of the last processed YAML token in the UTF-8 encoded YAML text.
public YamlTokenType TokenType { get; }
ValueIsEscapedLink to this heading
Lets the caller know whether the current Utf8YamlReader.ValueSpan or Utf8YamlReader.ValueSequence properties contain escape sequences per RFC 8259 section 7, and therefore require unescaping before being consumed.
public bool ValueIsEscaped { get; }
ValueSequenceLink to this heading
Gets the value of the last processed token as a ReadOnlySpan<byte> slice of the input payload. If the YAML is provided within a ReadOnlySequence<byte> and the slice that represents the token value fits in a single segment, then Utf8YamlReader.ValueSpan will contain the sliced value since it can be represented as a span. Otherwise, the Utf8YamlReader.ValueSequence will contain the token value.
public ReadOnlySequence<byte> ValueSequence { get; }
If Utf8YamlReader.HasValueSequence is false, Utf8YamlReader.ValueSequence contains useless data, likely for a previous multi-segment token. Therefore, only access Utf8YamlReader.ValueSequence if Utf8YamlReader.HasValueSequence is true. Otherwise, the token value must be accessed from Utf8YamlReader.ValueSpan.
ValueSpanLink to this heading
Gets the value of the last processed token as a ReadOnlySpan<byte> slice of the input payload. If the YAML is provided within a ReadOnlySequence<byte> and the slice that represents the token value fits in a single segment, then Utf8YamlReader.ValueSpan will contain the sliced value since it can be represented as a span. Otherwise, the Utf8YamlReader.ValueSequence will contain the token value.
public ReadOnlySpan<byte> ValueSpan { get; }
If Utf8YamlReader.HasValueSequence is true, Utf8YamlReader.ValueSpan contains useless data, likely for a previous single-segment token. Therefore, only access Utf8YamlReader.ValueSpan if Utf8YamlReader.HasValueSequence is false. Otherwise, the token value must be accessed from Utf8YamlReader.ValueSequence.
MethodsLink to this heading
CopyStringLink to this heading
Copies the current YAML token value from the source, unescaped as a UTF-8 string to the destination buffer.
public int CopyString(Span<byte> utf8Destination);
Parameters
utf8Destination: A buffer to write the unescaped UTF-8 bytes into.
Returns: The number of bytes written to utf8Destination.
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of the YAML token that is not a string (i.e. other than YamlTokenType.String or YamlTokenType.PropertyName. Utf8YamlReader.TokenType It will also throw when the YAML string contains invalid UTF-8 bytes, or invalid UTF-16 surrogates. |
| ArgumentException | The destination buffer is too small to hold the unescaped value. |
Unlike Utf8YamlReader.GetString, this method does not support YamlTokenType.Null. This method will throw ArgumentException if the destination buffer is too small to hold the unescaped value. An appropriately sized buffer can be determined by consulting the length of either Utf8YamlReader.ValueSpan or Utf8YamlReader.ValueSequence, since the unescaped result is always less than or equal to the length of the encoded strings.
Copies the current YAML token value from the source, unescaped, and transcoded as a UTF-16 char buffer.
public int CopyString(Span<char> destination);
Parameters
destination: A buffer to write the transcoded UTF-16 characters into.
Returns: The number of characters written to destination.
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of the YAML token that is not a string (i.e. other than YamlTokenType.String or YamlTokenType.PropertyName. Utf8YamlReader.TokenType It will also throw when the YAML string contains invalid UTF-8 bytes, or invalid UTF-16 surrogates. |
| ArgumentException | The destination buffer is too small to hold the unescaped value. |
Unlike Utf8YamlReader.GetString, this method does not support YamlTokenType.Null. This method will throw ArgumentException if the destination buffer is too small to hold the unescaped value. An appropriately sized buffer can be determined by consulting the length of either Utf8YamlReader.ValueSpan or Utf8YamlReader.ValueSequence, since the unescaped result is always less than or equal to the length of the encoded strings.
CreateKeyReaderLink to this heading
Returns a reader over the current mapping key when the key is a collection (Utf8YamlReader.KeyKind is YamlKeyKind.Complex): it reads the key node's own tokens, from its start token to its end token, after which Utf8YamlReader.Read returns false.
public Utf8YamlReader CreateKeyReader();
| Exception | Condition |
|---|---|
| InvalidOperationException | The current token is not a YamlTokenType.PropertyName whose key is a collection: a scalar key is read from the token itself, and an alias key names its anchored node. |
The returned reader has this reader's options (schema, YamlReaderOptions.AcceptLenientScalars, comment handling), the document's %TAG handles, and the key's first line and column, so positions and errors point into the document. Its YamlReaderOptions.MaxDepth is this reader's less the current depth, so a key cannot nest deeper than a value at the same place. Utf8YamlReader.TokenStartIndex and Utf8YamlReader.BytesConsumed count from the key's first byte.
The whole key is in this reader's buffer when its YamlTokenType.PropertyName token is returned, also over a multi-segment input, so the returned reader always reads a contiguous span. It is valid until this reader moves. Anchors and aliases in the key are returned as tokens and are not resolved.
GetBooleanLink to this heading
Parses the current YAML token value from the source as a Boolean. Returns true if the TokenType is YamlTokenType.True and false if the TokenType is YamlTokenType.False.
public bool GetBoolean();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a boolean (i.e. YamlTokenType.True or YamlTokenType.False). Utf8YamlReader.TokenType |
GetByteLink to this heading
Parses the current YAML token value from the source as a Byte. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Byte value. Throws exceptions otherwise.
public byte GetByte();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than Byte.MinValue or greater than Byte.MaxValue. |
GetBytesFromBase64Link to this heading
Parses the current YAML token value from the source and decodes the Base64 encoded YAML string as bytes.
public byte[] GetBytesFromBase64();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
| FormatException | The YAML string contains data outside of the expected Base64 range, or if it contains invalid/more than two padding characters, or is incomplete (i.e. the YAML string length is not a multiple of 4). |
GetCommentLink to this heading
Parses the current YAML token value from the source as a comment, transcoded as a String.
public string GetComment();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of the YAML token that is not a comment. Utf8YamlReader.TokenType |
GetDateTimeLink to this heading
Parses the current YAML token value from the source as a DateTime. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a DateTime value. Throws exceptions otherwise.
public DateTime GetDateTime();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is of an unsupported format. Only a subset of ISO 8601 formats are supported. |
GetDateTimeOffsetLink to this heading
Parses the current YAML token value from the source as a DateTimeOffset. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a DateTimeOffset value. Throws exceptions otherwise.
public DateTimeOffset GetDateTimeOffset();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is of an unsupported format. Only a subset of ISO 8601 formats are supported. |
GetDecimalLink to this heading
Parses the current YAML token value from the source as a Decimal. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Decimal value. Throws exceptions otherwise.
public decimal GetDecimal();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value represents a number less than Decimal.MinValue or greater than Decimal.MaxValue. |
GetDoubleLink to this heading
Parses the current YAML token value from the source as a Double. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Double value. Throws exceptions otherwise.
public double GetDouble();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | On any framework that is not .NET Core 3.0 or higher, thrown if the YAML token value represents a number less than Double.MinValue or greater than Double.MaxValue. |
GetExpandedTagLink to this heading
Gets the tag of the current node with its handle expanded (YAML 1.2 section 6.8.2), or null when the node has no tag: !e!foo after %TAG !e! tag:example.com,2000: gives tag:example.com,2000:foo, !!str gives tag:yaml.org,2002:str, a percent-encoded suffix is decoded, a verbatim tag (!<tag:x>) gives its content and the non-specific ! stays !. Utf8YamlReader.Tag keeps the tag as written.
public string? GetExpandedTag();
This method allocates the returned string; Utf8YamlReader.TryCopyExpandedTag does not allocate.
GetGuidLink to this heading
Parses the current YAML token value from the source as a Guid. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Guid value. Throws exceptions otherwise.
public Guid GetGuid();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is of an unsupported format for a Guid. |
GetInt16Link to this heading
Parses the current YAML token value from the source as a Int16. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Int16 value. Throws exceptions otherwise.
public short GetInt16();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than Int16.MinValue or greater than Int16.MaxValue. |
GetInt32Link to this heading
Parses the current YAML token value from the source as an Int32. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to an Int32 value. Throws exceptions otherwise.
public int GetInt32();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than Int32.MinValue or greater than Int32.MaxValue. |
GetInt64Link to this heading
Parses the current YAML token value from the source as a Int64. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Int64 value. Throws exceptions otherwise.
public long GetInt64();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than Int64.MinValue or greater than Int64.MaxValue. |
GetSByteLink to this heading
Parses the current YAML token value from the source as an SByte. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to an SByte value. Throws exceptions otherwise.
public sbyte GetSByte();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than SByte.MinValue or greater than SByte.MaxValue. |
GetSingleLink to this heading
Parses the current YAML token value from the source as a Single. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a Single value. Throws exceptions otherwise.
public float GetSingle();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | On any framework that is not .NET Core 3.0 or higher, thrown if the YAML token value represents a number less than Single.MinValue or greater than Single.MaxValue. |
GetStringLink to this heading
Parses the current YAML token value from the source, unescaped, and transcoded as a String.
public string? GetString();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of the YAML token that is not a string (i.e. other than YamlTokenType.String, YamlTokenType.PropertyName or YamlTokenType.Null). Utf8YamlReader.TokenType It will also throw when the YAML string contains invalid UTF-8 bytes, or invalid UTF-16 surrogates. |
Returns null when Utf8YamlReader.TokenType is YamlTokenType.Null.
GetUInt16Link to this heading
Parses the current YAML token value from the source as a UInt16. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a UInt16 value. Throws exceptions otherwise.
public ushort GetUInt16();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than UInt16.MinValue or greater than UInt16.MaxValue. |
GetUInt32Link to this heading
Parses the current YAML token value from the source as a UInt32. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a UInt32 value. Throws exceptions otherwise.
public uint GetUInt32();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than UInt32.MinValue or greater than UInt32.MaxValue. |
GetUInt64Link to this heading
Parses the current YAML token value from the source as a UInt64. Returns the value if the entire UTF-8 encoded token value can be successfully parsed to a UInt64 value. Throws exceptions otherwise.
public ulong GetUInt64();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
| FormatException | Thrown if the YAML token value is either of incorrect numeric format (for example if it contains a decimal or is written in scientific notation) or, it represents a number less than UInt64.MinValue or greater than UInt64.MaxValue. |
ReadLink to this heading
Read the next YAML token from input source.
public bool Read();
Returns: True if the token was read successfully, else false.
| Exception | Condition |
|---|---|
| YamlException | Thrown when an invalid YAML token is encountered according to the YAML 1.2 specification or if the current depth exceeds the recursive limit set by the max depth. |
SkipLink to this heading
Skips the children of the current YAML token.
public void Skip();
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown when the reader was given partial data with more data to follow (i.e. Utf8YamlReader.IsFinalBlock is false). |
| YamlException | Thrown when an invalid YAML token is encountered while skipping, according to the YAML 1.2 specification, or if the current depth exceeds the recursive limit set by the max depth. |
When Utf8YamlReader.TokenType is YamlTokenType.PropertyName, the reader first moves to the property value. When Utf8YamlReader.TokenType (originally, or after advancing) is YamlTokenType.StartObject or YamlTokenType.StartArray, the reader advances to the matching YamlTokenType.EndObject or YamlTokenType.EndArray. For all other token types, the reader does not move. After the next call to Utf8YamlReader.Read, the reader will be at the next value (when in an array), the next property name (when in an object), or the end array/object token.
TryCopyExpandedTagLink to this heading
Copies the UTF-8 bytes of the current node's expanded tag (see Utf8YamlReader.GetExpandedTag) to utf8Destination. Returns false, and writes nothing, when the destination is too short; bytesWritten is 0 when the node has no tag.
public bool TryCopyExpandedTag(Span<byte> utf8Destination, out int bytesWritten);
TryGetByteLink to this heading
Parses the current YAML token value from the source as a Byte. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Byte value. Returns false otherwise.
public bool TryGetByte(out byte value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetBytesFromBase64Link to this heading
Parses the current YAML token value from the source and decodes the Base64 encoded YAML string as bytes. Returns true if the entire token value is encoded as valid Base64 text and can be successfully decoded to bytes. Returns false otherwise.
public bool TryGetBytesFromBase64(out byte[]? value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
TryGetDateTimeLink to this heading
Parses the current YAML token value from the source as a DateTime. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a DateTime value. Returns false otherwise.
public bool TryGetDateTime(out DateTime value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
TryGetDateTimeOffsetLink to this heading
Parses the current YAML token value from the source as a DateTimeOffset. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a DateTimeOffset value. Returns false otherwise.
public bool TryGetDateTimeOffset(out DateTimeOffset value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
TryGetDecimalLink to this heading
Parses the current YAML token value from the source as a Decimal. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Decimal value. Returns false otherwise.
public bool TryGetDecimal(out decimal value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetDoubleLink to this heading
Parses the current YAML token value from the source as a Double. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Double value. Returns false otherwise.
public bool TryGetDouble(out double value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetGuidLink to this heading
Parses the current YAML token value from the source as a Guid. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Guid value. Only supports Guid values with hyphens and without any surrounding decorations. Returns false otherwise.
public bool TryGetGuid(out Guid value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.String. Utf8YamlReader.TokenType |
TryGetInt16Link to this heading
Parses the current YAML token value from the source as a Int16. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Int16 value. Returns false otherwise.
public bool TryGetInt16(out short value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetInt32Link to this heading
Parses the current YAML token value from the source as an Int32. Returns true if the entire UTF-8 encoded token value can be successfully parsed to an Int32 value. Returns false otherwise.
public bool TryGetInt32(out int value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetInt64Link to this heading
Parses the current YAML token value from the source as a Int64. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Int64 value. Returns false otherwise.
public bool TryGetInt64(out long value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetSByteLink to this heading
Parses the current YAML token value from the source as an SByte. Returns true if the entire UTF-8 encoded token value can be successfully parsed to an SByte value. Returns false otherwise.
public bool TryGetSByte(out sbyte value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetSingleLink to this heading
Parses the current YAML token value from the source as a Single. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a Single value. Returns false otherwise.
public bool TryGetSingle(out float value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetUInt16Link to this heading
Parses the current YAML token value from the source as a UInt16. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a UInt16 value. Returns false otherwise.
public bool TryGetUInt16(out ushort value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetUInt32Link to this heading
Parses the current YAML token value from the source as a UInt32. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a UInt32 value. Returns false otherwise.
public bool TryGetUInt32(out uint value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TryGetUInt64Link to this heading
Parses the current YAML token value from the source as a UInt64. Returns true if the entire UTF-8 encoded token value can be successfully parsed to a UInt64 value. Returns false otherwise.
public bool TryGetUInt64(out ulong value);
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to get the value of a YAML token that is not a YamlTokenType.Number. Utf8YamlReader.TokenType |
TrySkipLink to this heading
Tries to skip the children of the current YAML token.
public bool TrySkip();
Returns: True if there was enough data for the children to be skipped successfully, else false.
| Exception | Condition |
|---|---|
| YamlException | Thrown when an invalid YAML token is encountered while skipping, according to the YAML 1.2 specification, or if the current depth exceeds the recursive limit set by the max depth. |
If the reader did not have enough data to completely skip the children of the current token, it will be reset to the state it was in before the method was called.
When Utf8YamlReader.TokenType is YamlTokenType.PropertyName, the reader first moves to the property value. When Utf8YamlReader.TokenType (originally, or after advancing) is YamlTokenType.StartObject or YamlTokenType.StartArray, the reader advances to the matching YamlTokenType.EndObject or YamlTokenType.EndArray. For all other token types, the reader does not move. After the next call to Utf8YamlReader.Read, the reader will be at the next value (when in an array), the next property name (when in an object), or the end array/object token.
ValueTextEqualsLink to this heading
Compares the UTF-8 encoded text to the unescaped YAML token value in the source and returns true if they match.
public bool ValueTextEquals(ReadOnlySpan<byte> utf8Text);
Parameters
utf8Text: The UTF-8 encoded text to compare against.
Returns: True if the YAML token value in the source matches the UTF-8 encoded look up text.
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to find a text match on a YAML token that is not a string (i.e. other than YamlTokenType.String or YamlTokenType.PropertyName). Utf8YamlReader.TokenType |
If the look up text is invalid UTF-8 text, the method will return false since you cannot have invalid UTF-8 within the YAML payload.
The comparison of the YAML token value in the source and the look up text is done by first unescaping the YAML value in source, if required. The look up text is matched as is, without any modifications to it.
Compares the string text to the unescaped YAML token value in the source and returns true if they match.
public bool ValueTextEquals(string? text);
Parameters
text: The text to compare against.
Returns: True if the YAML token value in the source matches the look up text.
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to find a text match on a YAML token that is not a string (i.e. other than YamlTokenType.String or YamlTokenType.PropertyName). Utf8YamlReader.TokenType |
If the look up text is invalid UTF-8 text, the method will return false since you cannot have invalid UTF-8 within the YAML payload.
The comparison of the YAML token value in the source and the look up text is done by first unescaping the YAML value in source, if required. The look up text is matched as is, without any modifications to it.
Compares the text to the unescaped YAML token value in the source and returns true if they match.
public bool ValueTextEquals(ReadOnlySpan<char> text);
Parameters
text: The text to compare against.
Returns: True if the YAML token value in the source matches the look up text.
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if trying to find a text match on a YAML token that is not a string (i.e. other than YamlTokenType.String or YamlTokenType.PropertyName). Utf8YamlReader.TokenType |
If the look up text is invalid or incomplete UTF-16 text (i.e. unpaired surrogates), the method will return false since you cannot have invalid UTF-16 within the YAML payload.
The comparison of the YAML token value in the source and the look up text is done by first unescaping the YAML value in source, if required. The look up text is matched as is, without any modifications to it.