TomlParser Class

Parses TOML into an incremental event stream.

public sealed class TomlParser

Properties

NameDescription
CurrentGets the current parse event.
DepthGets the current event depth.
DiagnosticsGets diagnostics produced by the parser.
HasErrorsGets a value indicating whether diagnostics include errors.
ParserOptionsGets the parser options.
SourceNameGets the optional source name associated with the parsed payload.

Gets the current parse event.

public ref readonly TomlParseEvent Current { get; }

Property value

TomlParseEvent

Gets the current event depth.

public int Depth { get; }

Property value

int

Diagnostics

TomlParser.cs

Gets diagnostics produced by the parser.

public DiagnosticsBag Diagnostics { get; }

Property value

DiagnosticsBag

HasErrors

TomlParser.cs

Gets a value indicating whether diagnostics include errors.

public bool HasErrors { get; }

Property value

bool

ParserOptions

TomlParser.cs

Gets the parser options.

public TomlParserOptions ParserOptions { get; }

Property value

TomlParserOptions

SourceName

TomlParser.cs

Gets the optional source name associated with the parsed payload.

public string? SourceName { get; }

Property value

string?

Methods

NameDescription
Create(TextReader, TomlParserOptions, TomlSerializerOptions?)Creates a parser over TOML text from a TextReader.
Create(TextReader, TomlSerializerOptions?)Creates a parser over TOML text from a TextReader.
Create(string, TomlParserOptions, TomlSerializerOptions?)Creates a parser over a TOML string.
Create(string, TomlSerializerOptions?)Creates a parser over a TOML string.
GetPropertyName()Gets the current property name by decoding it from the original TOML input.
GetString()Gets the current string scalar value by decoding it from the original TOML input.
MoveNext()Advances to the next parse event.

Create overloads

Create(TextReader, TomlParserOptions, TomlSerializerOptions?)

TomlParser.cs

Creates a parser over TOML text from a TextReader.

public static TomlParser Create(TextReader reader, TomlParserOptions parserOptions, TomlSerializerOptions? options = null)
Parameters
reader TextReader
The text reader.
parserOptions TomlParserOptions
Parser options controlling error handling.
options TomlSerializerOptions?
Optional parser/serializer options.
Returns

TomlParser A parser instance positioned before the first event.

Exceptions
TomlException
The input is longer than TomlSerializerOptions.MaxInputLength.
ArgumentNullException
reader is null.
ArgumentNullException
parserOptions is null.

Create(TextReader, TomlSerializerOptions?)

TomlParser.cs

Creates a parser over TOML text from a TextReader.

public static TomlParser Create(TextReader reader, TomlSerializerOptions? options = null)
Parameters
reader TextReader
The text reader.
options TomlSerializerOptions?
Optional parser/serializer options.
Returns

TomlParser A parser instance positioned before the first event.

Exceptions
TomlException
The input is longer than TomlSerializerOptions.MaxInputLength.
ArgumentNullException
reader is null.

Create(string, TomlParserOptions, TomlSerializerOptions?)

TomlParser.cs

Creates a parser over a TOML string.

public static TomlParser Create(string toml, TomlParserOptions parserOptions, TomlSerializerOptions? options = null)
Parameters
toml string
The TOML payload.
parserOptions TomlParserOptions
Parser options controlling error handling.
options TomlSerializerOptions?
Optional parser/serializer options.
Returns

TomlParser A parser instance positioned before the first event.

Exceptions
TomlException
The input is longer than TomlSerializerOptions.MaxInputLength.
ArgumentNullException
toml is null.
ArgumentNullException
parserOptions is null.

Create(string, TomlSerializerOptions?)

TomlParser.cs

Creates a parser over a TOML string.

public static TomlParser Create(string toml, TomlSerializerOptions? options = null)
Parameters
toml string
The TOML payload.
options TomlSerializerOptions?
Optional parser/serializer options.
Returns

TomlParser A parser instance positioned before the first event.

Exceptions
TomlException
The input is longer than TomlSerializerOptions.MaxInputLength.
ArgumentNullException
toml is null.

GetPropertyName()

TomlParser.cs

Gets the current property name by decoding it from the original TOML input.

public string GetPropertyName()

Returns

string The decoded property name.

Exceptions

InvalidOperationException
The current event is not a property name.

GetString()

TomlParser.cs

Gets the current string scalar value by decoding it from the original TOML input.

public string GetString()

Returns

string The decoded string value.

Exceptions

InvalidOperationException
The current event is not a string scalar.

MoveNext()

TomlParser.cs

Advances to the next parse event.

public bool MoveNext()

Returns

bool true when a parse event is available; otherwise false.

Exceptions

TomlException
The TOML payload is invalid and TomlParserOptions.Mode is TomlParserMode.Strict.