Table of Contents

Bodu.Text.Toml.Document Namespace

Package

Bodu.Text.Toml.Document

Purpose

Bodu.Text.Toml.Document is the read-only document object model of Bodu.Text.Toml, shaped after System.Text.Json's JsonDocument / JsonElement. A parse produces a single disposable TomlDocument that indexes the input once; every TomlElement is a lightweight struct cursor into that index. Prefer it over the mutable Bodu.Text.Toml.Nodes tier for inspection, and note that an object-typed member deserialized by the TomlSerializer reads back as a TomlElement.

Key types

  • TomlDocument - the disposable owner: Parse (from string or ReadOnlySpan<byte>) and RootElement.
  • TomlElement - the value cursor: ValueKind, the scalar accessors GetString / GetInt64 / GetDouble / GetBoolean / GetDateTimeOffset / GetDateTime / GetDateOnly / GetTimeOnly, GetProperty / TryGetProperty, an integer indexer, GetArrayLength, EnumerateArray / EnumerateObject, and WriteTo.
  • TomlElement.ArrayEnumerator / TomlElement.ObjectEnumerator - the struct enumerators returned by EnumerateArray / EnumerateObject.
  • TomlProperty - a Name / Value pair yielded by EnumerateObject.
  • TomlDocumentOptions - SpecVersion and MaxDepth.

Example

using Bodu.Text.Toml.Document;

using TomlDocument document = TomlDocument.Parse("[server]\nhost = \"localhost\"\nport = 8080\n");
TomlElement server = document.RootElement.GetProperty("server");

long port = server.GetProperty("port").GetInt64();
foreach (TomlProperty property in server.EnumerateObject())
    Console.WriteLine($"{property.Name}: {property.Value.ValueKind}");

Notes

Classes

TomlDocument

Provides a read-only, high-performance document object model over TOML text, exposed as a flat index of row records through lightweight TomlElement struct views rather than a tree of node objects.

Structs

TomlDocumentOptions

Defines the customizations applied when parsing a TomlDocument.

TomlElement

Represents a single read-only value within a TomlDocument. The element is a lightweight view - a pair of the owning document and a row index - so copying it is cheap and never materializes a node.

TomlElement.ArrayEnumerator

Enumerates the elements of an array TomlElement in order.

TomlElement.ObjectEnumerator

Enumerates the key/value pairs of a table TomlElement in stored order.

TomlProperty

Represents a single key/value pair within a table TomlElement. Instances are produced by TomlElement.ObjectEnumerator.