YamlScalar Class
Provides YAML scalar parsing helpers aligned with the YAML 1.2 core schema conventions used by YamlSerializer.
public static class YamlScalarMethods
| Name | Description |
|---|---|
| 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.csDetermines whether the current scalar token represents YAML null while honoring scalar style and YamlSerializerOptions.UseSchema.
public static bool IsNull(YamlReader reader)IsNull(ReadOnlySpan<char>)
YamlScalar.csDetermines whether a scalar represents YAML null (for example null or ~).
public static bool IsNull(ReadOnlySpan<char> value)ResolveObject(YamlReader)
YamlScalar.csResolves the current scalar token to the CLR value implied by the scalar style, tag, and schema options.
public static object? ResolveObject(YamlReader reader)TryParseBool overloads
TryParseBool(YamlReader, bool)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultbool- The parsed boolean value.
Returns
TryParseBool(ReadOnlySpan<char>, bool)
YamlScalar.csParses a YAML boolean scalar (true/false).
public static bool TryParseBool(ReadOnlySpan<char> value, out bool result)TryParseCultureInfo(string?, CultureInfo?)
YamlScalar.csParses a YAML scalar as a CultureInfo from its culture name (for example fr-FR).
public static bool TryParseCultureInfo(string? value, out CultureInfo? result)Parameters
valuestring?- The culture name to parse. An empty name resolves to
CultureInfo.InvariantCulture. resultCultureInfo?- The parsed culture.
Returns
TryParseDecimal overloads
TryParseDecimal(YamlReader, decimal)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultdecimal- The parsed decimal value.
Returns
TryParseDecimal(ReadOnlySpan<char>, decimal)
YamlScalar.csParses a YAML floating-point scalar into Decimal.
public static bool TryParseDecimal(ReadOnlySpan<char> value, out decimal result)TryParseDouble overloads
TryParseDouble(YamlReader, double)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultdouble- The parsed floating-point value.
Returns
TryParseDouble(ReadOnlySpan<char>, double)
YamlScalar.csParses a YAML floating-point scalar into Double, including .inf and .nan.
public static bool TryParseDouble(ReadOnlySpan<char> value, out double result)TryParseIeee754 overloads
TryParseIeee754<T>(YamlReader, T)
YamlScalar.csAvailable 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
readerYamlReader- The reader positioned on a scalar token.
resultT- The parsed floating-point value.
Returns
TryParseIeee754<T>(ReadOnlySpan<char>, T)
YamlScalar.csAvailable 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
valueReadOnlySpan<char>- The scalar text to parse.
resultT- The parsed floating-point value.
Returns
TryParseInt32 overloads
TryParseInt32(YamlReader, int)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultint- The parsed integer value.
Returns
TryParseInt32(ReadOnlySpan<char>, int)
YamlScalar.csParses a YAML integer scalar into Int32.
public static bool TryParseInt32(ReadOnlySpan<char> value, out int result)TryParseInt64 overloads
TryParseInt64(YamlReader, long)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultlong- The parsed integer value.
Returns
TryParseInt64(ReadOnlySpan<char>, long)
YamlScalar.csParses 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)TryParseUInt32 overloads
TryParseUInt32(YamlReader, uint)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultuint- The parsed unsigned integer value.
Returns
TryParseUInt32(ReadOnlySpan<char>, uint)
YamlScalar.csParses a YAML integer scalar into UInt32.
public static bool TryParseUInt32(ReadOnlySpan<char> value, out uint result)TryParseUInt64 overloads
TryParseUInt64(YamlReader, ulong)
YamlScalar.csParses 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
readerYamlReader- The reader positioned on a scalar token.
resultulong- The parsed unsigned integer value.
Returns
TryParseUInt64(ReadOnlySpan<char>, ulong)
YamlScalar.csParses 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)