TomlReader Class
Reads TOML tokens for use by TomlConverter implementations.
public sealed class TomlReaderRemarks
The reader parses the whole document on the first TomlReader.Read, and returns the keys of a table defined in several places (for example an array of tables reopened after another table) as a single table.
Properties
| Name | Description |
|---|---|
| Column | Gets the current column number (1-based). |
| CurrentSpan | Gets the optional source span associated with the current token. |
| IsInlineContainer | Gets a value indicating whether the current TomlTokenType.StartTable or TomlTokenType.StartArray token starts an inline table ({) or an inline array ([). |
| Line | Gets the current line number (1-based). |
| Options | Gets the serializer options associated with this reader instance. |
| PropertyName | Gets the current property name when TomlReader.TokenType is TomlTokenType.PropertyName. |
| SourceName | Gets the optional source name associated with the TOML payload (for example, a file path). |
| TokenType | Gets the current token type. |
Column
TomlReader.csCurrentSpan
TomlReader.csGets the optional source span associated with the current token.
public TomlSourceSpan? CurrentSpan { get; }Property value
IsInlineContainer
TomlReader.csGets a value indicating whether the current TomlTokenType.StartTable or TomlTokenType.StartArray token starts an inline table ({) or an inline array ([).
public bool IsInlineContainer { get; }Property value
Remarks
It is false for a table or an array of tables opened by a header or a dotted key, which a later header or dotted key can extend, and for any other token.
Line
TomlReader.csOptions
TomlReader.csGets the serializer options associated with this reader instance.
public TomlSerializerOptions Options { get; }Property value
PropertyName
TomlReader.csGets the current property name when TomlReader.TokenType is TomlTokenType.PropertyName.
public string? PropertyName { get; }Property value
SourceName
TomlReader.csTokenType
TomlReader.csMethods
| Name | Description |
|---|---|
| Create(TextReader, TomlSerializerOptions?) | Creates a TOML reader over a text reader. |
| Create(string, TomlSerializerOptions?) | Creates a TOML reader over a string payload. |
| CreateException(string) | Creates a TomlException with the current source location (when available). |
| GetBoolean() | Gets the current boolean value. |
| GetDecimal() | Gets the current floating value as decimal. |
| GetDouble() | Gets the current floating value. |
| GetInt64() | Gets the current integer value. |
| GetRawText() | Gets the raw source text represented by the current token. |
| GetString() | Gets the current string value. |
| GetTomlDateTime() | Gets the current TOML datetime value. |
| PropertyNameEquals(string) | Checks whether the current property name matches the expected value, using an ordinal, case-sensitive comparison. |
| Read() | Advances the reader to the next token. |
| Skip() | Skips the current value. |
| TryGetPropertyNameHash(ulong) | Attempts to get a stable hash for the current property name without materializing it. |
Create overloads
Create(TextReader, TomlSerializerOptions?)
TomlReader.csCreates a TOML reader over a text reader.
public static TomlReader Create(TextReader reader, TomlSerializerOptions? options = null)Parameters
readerTextReaderoptionsTomlSerializerOptions?
Returns
Exceptions
TomlException- The input is longer than
TomlSerializerOptions.MaxInputLength.
Create(string, TomlSerializerOptions?)
TomlReader.csCreates a TOML reader over a string payload.
public static TomlReader Create(string toml, TomlSerializerOptions? options = null)Parameters
tomlstringoptionsTomlSerializerOptions?
Returns
Exceptions
TomlException- The input is longer than
TomlSerializerOptions.MaxInputLength.
CreateException(string)
TomlReader.csCreates a TomlException with the current source location (when available).
public TomlException CreateException(string message)GetBoolean()
TomlReader.csGetDecimal()
TomlReader.csGets the current floating value as decimal.
public decimal GetDecimal()GetDouble()
TomlReader.csGetInt64()
TomlReader.csGetRawText()
TomlReader.csGets the raw source text represented by the current token.
public string GetRawText()Returns
Exceptions
TomlException- The current token does not have a source span.
Remarks
This API is intended for custom converters that need to preserve the original literal (for example, to implement exact parsing).
GetString()
TomlReader.csGetTomlDateTime()
TomlReader.csPropertyNameEquals(string)
TomlReader.csChecks whether the current property name matches the expected value, using an ordinal, case-sensitive comparison.
Parameters
expectedstring- The expected property name.
Returns
bool true when the property name matches; otherwise false.
Exceptions
ArgumentNullExceptionexpectedisnull.TomlException- The current token does not have a source span.
Read()
TomlReader.csAdvances the reader to the next token.
public bool Read()Returns
Exceptions
TomlException- The TOML document is invalid. The first call reports errors anywhere in the document.
Skip()
TomlReader.csSkips the current value.
public void Skip()TryGetPropertyNameHash(ulong)
TomlReader.csAttempts to get a stable hash for the current property name without materializing it.