YamlScalar Class

Provides YAML scalar parsing helpers aligned with the YAML 1.2 core schema conventions used by YamlSerializer.

public static class YamlScalar

Methods

NameDescription
IsNull(YamlReader)Determines whether the current scalar token represents YAML null while honoring scalar style and YamlSerializerOptions.UseSchema.
IsNull(ReadOnlySpan<char>)Determines whether a scalar represents YAML null (for example null or ~).
ResolveObject(YamlReader)Resolves the current scalar token to the CLR value implied by the scalar style, tag, and schema options.
TryParseBool(YamlReader, bool)Parses the current scalar token as a YAML boolean while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseBool(ReadOnlySpan<char>, bool)Parses a YAML boolean scalar (true/false).
TryParseCultureInfo(string?, CultureInfo?)Parses a YAML scalar as a CultureInfo from its culture name (for example fr-FR).
TryParseDecimal(YamlReader, decimal)Parses the current scalar token as a YAML decimal value while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseDecimal(ReadOnlySpan<char>, decimal)Parses a YAML floating-point scalar into Decimal.
TryParseDouble(YamlReader, double)Parses the current scalar token as a YAML floating-point value while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseDouble(ReadOnlySpan<char>, double)Parses a YAML floating-point scalar into Double, including .inf and .nan.
TryParseIeee754<T>(YamlReader, T)Parses the current scalar token as an IEEE 754 floating-point value while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseIeee754<T>(ReadOnlySpan<char>, T)Parses a YAML floating-point scalar into an IEEE 754 floating-point type, including .inf and .nan.
TryParseInt32(YamlReader, int)Parses the current scalar token as a YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseInt32(ReadOnlySpan<char>, int)Parses a YAML integer scalar into Int32.
TryParseInt64(YamlReader, long)Parses the current scalar token as a YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseInt64(ReadOnlySpan<char>, long)Parses a YAML integer scalar into Int64, including common base prefixes (0x, 0o, 0b) and underscores.
TryParseUInt32(YamlReader, uint)Parses the current scalar token as an unsigned YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseUInt32(ReadOnlySpan<char>, uint)Parses a YAML integer scalar into UInt32.
TryParseUInt64(YamlReader, ulong)Parses the current scalar token as an unsigned YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.
TryParseUInt64(ReadOnlySpan<char>, ulong)Parses a YAML integer scalar into UInt64, including common base prefixes (0x, 0o, 0b) and underscores.

IsNull overloads

IsNull(YamlReader)

YamlScalar.cs

Determines whether the current scalar token represents YAML null while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool IsNull(YamlReader reader)
Parameters
reader YamlReader
The reader positioned on a scalar token.
Returns

bool

IsNull(ReadOnlySpan<char>)

YamlScalar.cs

Determines whether a scalar represents YAML null (for example null or ~).

public static bool IsNull(ReadOnlySpan<char> value)
Parameters
value ReadOnlySpan<char>
Returns

bool

ResolveObject(YamlReader)

YamlScalar.cs

Resolves the current scalar token to the CLR value implied by the scalar style, tag, and schema options.

public static object? ResolveObject(YamlReader reader)

Parameters

reader YamlReader
The reader positioned on a scalar token.

Returns

object?

TryParseBool overloads

TryParseBool(YamlReader, bool)

YamlScalar.cs

Parses the current scalar token as a YAML boolean while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseBool(YamlReader reader, out bool result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result bool
The parsed boolean value.
Returns

bool

TryParseBool(ReadOnlySpan<char>, bool)

YamlScalar.cs

Parses a YAML boolean scalar (true/false).

public static bool TryParseBool(ReadOnlySpan<char> value, out bool result)
Parameters
value ReadOnlySpan<char>
result bool
Returns

bool

TryParseCultureInfo(string?, CultureInfo?)

YamlScalar.cs

Parses a YAML scalar as a CultureInfo from its culture name (for example fr-FR).

public static bool TryParseCultureInfo(string? value, out CultureInfo? result)

Parameters

value string?
The culture name to parse. An empty name resolves to CultureInfo.InvariantCulture.
result CultureInfo?
The parsed culture.

Returns

bool

TryParseDecimal overloads

TryParseDecimal(YamlReader, decimal)

YamlScalar.cs

Parses the current scalar token as a YAML decimal value while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseDecimal(YamlReader reader, out decimal result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result decimal
The parsed decimal value.
Returns

bool

TryParseDecimal(ReadOnlySpan<char>, decimal)

YamlScalar.cs

Parses a YAML floating-point scalar into Decimal.

public static bool TryParseDecimal(ReadOnlySpan<char> value, out decimal result)
Parameters
value ReadOnlySpan<char>
result decimal
Returns

bool

TryParseDouble overloads

TryParseDouble(YamlReader, double)

YamlScalar.cs

Parses the current scalar token as a YAML floating-point value while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseDouble(YamlReader reader, out double result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result double
The parsed floating-point value.
Returns

bool

TryParseDouble(ReadOnlySpan<char>, double)

YamlScalar.cs

Parses a YAML floating-point scalar into Double, including .inf and .nan.

public static bool TryParseDouble(ReadOnlySpan<char> value, out double result)
Parameters
value ReadOnlySpan<char>
result double
Returns

bool

TryParseIeee754 overloads

TryParseIeee754<T>(YamlReader, T)

YamlScalar.cs

Available in: net11.0(not available in the other target frameworks of the package)

Parses the current scalar token as an IEEE 754 floating-point value while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseIeee754<T>(YamlReader reader, out T result) where T : struct, IFloatingPointIeee754<T>
Type parameters
T
The IEEE 754 floating-point type to parse.
Parameters
reader YamlReader
The reader positioned on a scalar token.
result T
The parsed floating-point value.
Returns

bool

TryParseIeee754<T>(ReadOnlySpan<char>, T)

YamlScalar.cs

Available in: net11.0(not available in the other target frameworks of the package)

Parses a YAML floating-point scalar into an IEEE 754 floating-point type, including .inf and .nan.

public static bool TryParseIeee754<T>(ReadOnlySpan<char> value, out T result) where T : struct, IFloatingPointIeee754<T>
Type parameters
T
The IEEE 754 floating-point type to parse.
Parameters
value ReadOnlySpan<char>
The scalar text to parse.
result T
The parsed floating-point value.
Returns

bool

TryParseInt32 overloads

TryParseInt32(YamlReader, int)

YamlScalar.cs

Parses the current scalar token as a YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseInt32(YamlReader reader, out int result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result int
The parsed integer value.
Returns

bool

TryParseInt32(ReadOnlySpan<char>, int)

YamlScalar.cs

Parses a YAML integer scalar into Int32.

public static bool TryParseInt32(ReadOnlySpan<char> value, out int result)
Parameters
value ReadOnlySpan<char>
result int
Returns

bool

TryParseInt64 overloads

TryParseInt64(YamlReader, long)

YamlScalar.cs

Parses the current scalar token as a YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseInt64(YamlReader reader, out long result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result long
The parsed integer value.
Returns

bool

TryParseInt64(ReadOnlySpan<char>, long)

YamlScalar.cs

Parses a YAML integer scalar into Int64, including common base prefixes (0x, 0o, 0b) and underscores.

public static bool TryParseInt64(ReadOnlySpan<char> value, out long result)
Parameters
value ReadOnlySpan<char>
result long
Returns

bool

TryParseUInt32 overloads

TryParseUInt32(YamlReader, uint)

YamlScalar.cs

Parses the current scalar token as an unsigned YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseUInt32(YamlReader reader, out uint result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result uint
The parsed unsigned integer value.
Returns

bool

TryParseUInt32(ReadOnlySpan<char>, uint)

YamlScalar.cs

Parses a YAML integer scalar into UInt32.

public static bool TryParseUInt32(ReadOnlySpan<char> value, out uint result)
Parameters
value ReadOnlySpan<char>
result uint
Returns

bool

TryParseUInt64 overloads

TryParseUInt64(YamlReader, ulong)

YamlScalar.cs

Parses the current scalar token as an unsigned YAML integer while honoring scalar style and YamlSerializerOptions.UseSchema.

public static bool TryParseUInt64(YamlReader reader, out ulong result)
Parameters
reader YamlReader
The reader positioned on a scalar token.
result ulong
The parsed unsigned integer value.
Returns

bool

TryParseUInt64(ReadOnlySpan<char>, ulong)

YamlScalar.cs

Parses a YAML integer scalar into UInt64, including common base prefixes (0x, 0o, 0b) and underscores.

public static bool TryParseUInt64(ReadOnlySpan<char> value, out ulong result)
Parameters
value ReadOnlySpan<char>
result ulong
Returns

bool