Bodu.Text.Toml.Document Namespace
- Package
-
Bodu.Text.Toml 1.0.0
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(fromstringorReadOnlySpan<byte>) andRootElement. - TomlElement - the value cursor:
ValueKind, the scalar accessorsGetString/GetInt64/GetDouble/GetBoolean/GetDateTimeOffset/GetDateTime/GetDateOnly/GetTimeOnly,GetProperty/TryGetProperty, an integer indexer,GetArrayLength,EnumerateArray/EnumerateObject, andWriteTo. - TomlElement.ArrayEnumerator / TomlElement.ObjectEnumerator - the struct enumerators returned by
EnumerateArray/EnumerateObject. - TomlProperty - a
Name/Valuepair yielded byEnumerateObject. - TomlDocumentOptions -
SpecVersionandMaxDepth.
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
- Lifetime. Elements are only valid while their document is undisposed.
- Kind-checked accessors. Calling an accessor that does not match
ValueKindthrows InvalidOperationException; checkValueKind(a TomlValueKind) first when the shape is not known. - See also: the Bodu.Text.Toml introduction and the Using TOML guide (Pattern 7 - Inspect a document with the read-only DOM).
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.