TomlDocument Class
A read-only, high-performance representation of a TOML document, over its UTF-8 bytes.
public sealed class TomlDocument : IDisposableRemarks
The document validates the whole TOML grammar, including the rules the Utf8TomlReader does not check: duplicate keys, tables defined twice, and inline tables or static arrays extended by other keys. A table defined in several parts of the document, such as [a], [b] and then [a.c], is one table.
The values are decoded when they are read, so parsing does not allocate per value. The document uses pooled memory: dispose it once its elements are no longer used. Use TomlElement.Clone to keep an element after that.
- Implements
Properties
| Name | Description |
|---|---|
| RootElement | Gets the root table of the document. |
| Utf8Text | Gets the UTF-8 text of the document. |
RootElement
TomlDocument.csUtf8Text
TomlDocument.csMethods
| Name | Description |
|---|---|
| Dispose() | Returns the pooled memory of the document. Its elements cannot be used anymore. |
| Parse(Stream, TomlDocumentOptions) | Parses a UTF-8 TOML document read from a stream. |
| Parse(ReadOnlyMemory<byte>, TomlDocumentOptions) | Parses a UTF-8 TOML document. The bytes are not copied, so they must not change while the document is used. |
| Parse(string, TomlDocumentOptions) | Parses a TOML document. |
| ParseAsync(Stream, TomlDocumentOptions, CancellationToken) | Parses a UTF-8 TOML document read from a stream. |
| WriteTo(Utf8TomlWriter) | Writes the document with a writer. |
Dispose()
TomlDocument.csReturns the pooled memory of the document. Its elements cannot be used anymore.
public void Dispose()Parse overloads
Parse(Stream, TomlDocumentOptions)
TomlDocument.csParses a UTF-8 TOML document read from a stream.
public static TomlDocument Parse(Stream utf8Toml, TomlDocumentOptions options = default)Parameters
utf8TomlStream- The stream to read, up to its end.
optionsTomlDocumentOptions- The options of the parser.
Returns
Exceptions
TomlException- The document is not valid TOML.
Parse(ReadOnlyMemory<byte>, TomlDocumentOptions)
TomlDocument.csParses a UTF-8 TOML document. The bytes are not copied, so they must not change while the document is used.
public static TomlDocument Parse(ReadOnlyMemory<byte> utf8Toml, TomlDocumentOptions options = default)Parameters
utf8TomlReadOnlyMemory<byte>- The UTF-8 bytes of the document. A UTF-8 byte order mark at the start is skipped.
optionsTomlDocumentOptions- The options of the parser.
Returns
Exceptions
TomlException- The document is not valid TOML.
Parse(string, TomlDocumentOptions)
TomlDocument.csParses a TOML document.
public static TomlDocument Parse(string toml, TomlDocumentOptions options = default)Parameters
tomlstring- The text of the document.
optionsTomlDocumentOptions- The options of the parser.
Returns
Exceptions
TomlException- The document is not valid TOML, or contains an unpaired surrogate.
ParseAsync(Stream, TomlDocumentOptions, CancellationToken)
TomlDocument.csParses a UTF-8 TOML document read from a stream.
net10.0
public static Task<TomlDocument> ParseAsync(Stream utf8Toml, TomlDocumentOptions options = default, CancellationToken cancellationToken = default)net11.0
public static Task<TomlDocument> ParseAsync(Stream utf8Toml, TomlDocumentOptions options = default, CancellationToken cancellationToken = default)Parameters
utf8TomlStream- The stream to read, up to its end.
optionsTomlDocumentOptions- The options of the parser.
cancellationTokenCancellationToken- A token to cancel the reading.
Returns
Exceptions
TomlException- The document is not valid TOML.
WriteTo(Utf8TomlWriter)
TomlDocument.csWrites the document with a writer.
public void WriteTo(Utf8TomlWriter writer)Parameters
writerUtf8TomlWriter- The writer.