Bodu.Text.Toml.Nodes Namespace
- Package
-
Bodu.Text.Toml 1.0.0
Purpose
Bodu.Text.Toml.Nodes is the mutable document object model of Bodu.Text.Toml, shaped after System.Text.Json.Nodes. Parse UTF-8 TOML into an editable tree, build one from scratch, change it, and write it back through the Utf8TomlWriter. For read-only inspection with fewer allocations, use the sibling Bodu.Text.Toml.Document tier; for typed binding, use the TomlSerializer.
Key types
- TomlNode - abstract base:
Parse,AsObject/AsArray/AsValue,GetValue<T>,GetValueKind,WriteTo,ToUtf8Bytes,DeepEquals, string and integer indexers, and implicit conversions from every TOML scalar CLR type. - TomlObject - a table node keyed by string, with
Add/Remove/TryGetValueand an indexer. - TomlArray - an array node implementing
IList<TomlNode?>. - TomlValue - a scalar leaf (string, integer, float, boolean, or one of the four date-time kinds), created via
Createand read viaGetValue<T>/TryGetValue<T>. - TomlNodeOptions - parsing options for
Parse.
Example
using Bodu.Text.Toml.Nodes;
TomlNode root = TomlNode.Parse("[server]\nhost = \"localhost\"\nport = 8080\n"u8)!;
root["server"]!["port"] = 9090; // implicit conversion from int
root["server"]!.AsObject().Add("tls", true); // implicit conversion from bool
byte[] back = root.ToUtf8Bytes();
Notes
- Table root. The root of a parsed or written tree is always a TomlObject; writing a scalar or array as the root throws.
- Layout is normalized. Comments and the original header/inline layout are not preserved; the writer re-emits the tree in canonical block form.
- See also: the Bodu.Text.Toml introduction and the Using TOML guide (Pattern 6 - Edit a document with the mutable DOM).
Classes
- TomlArray
Represents a mutable TOML array as an ordered, index-addressable collection of child nodes.
- TomlNode
Represents a single node in a mutable TOML document object model, serving as the base for the three concrete node kinds - TomlObject, TomlArray, and TomlValue.
- TomlObject
Represents a mutable TOML table as a string-keyed collection of child nodes.
- TomlValue
Represents a scalar TOML value within a node tree - one of the eight TOML scalar kinds: a string, a 64-bit integer, a floating-point number, a Boolean, or one of the four date-time kinds.
Structs
- TomlNodeOptions
Defines the customizations applied to a mutable TOML node tree.