Table of Contents

Bodu.Text.Ini.Nodes Namespace

Package

Bodu.Text.Ini.Nodes

Purpose

Bodu.Text.Ini.Nodes is the mutable, comment-preserving document object model of Bodu.Text.Ini: parse an INI file into an editable object-of-objects, change or add sections and entries, and write it back through the Utf8IniWriter with the human-authored comments intact. It is the one sanctioned trivia-bearing DOM among the line formats, intended for faithful rewrites of files people also edit by hand. For read-only lookup use the sibling Bodu.Text.Ini.Document tier; for typed binding use the IniSerializer.

Key types

  • IniNode - abstract base: Parse (from string or UTF-8 bytes, returning the root object), LeadingComments, AsObject / AsValue, ValueKind, DeepClone, WriteTo, ToUtf8Bytes, and an implicit conversion from string.
  • IniObject - the root or a section: Keys, Count, ContainsKey / TryGetValue / Remove, a string indexer that adds or replaces, and TrailingComments.
  • IniValue - a single entry with a settable Value.

Example

using Bodu.Text.Ini.Nodes;

IniObject root = IniNode.Parse("; owned by ops\n[server]\nhost=localhost\n"u8);
IniObject server = root["server"].AsObject();

var port = new IniValue("8080");
port.LeadingComments.Add("listening port");
server["port"] = port;

byte[] back = root.ToUtf8Bytes();   // "; owned by ops" survives

Notes

  • Two levels only. The root holds global entries and sections; a section holds entries. Nested sections are not modeled.
  • Comment placement. LeadingComments on an entry or section are emitted immediately before it (the root object's own list is never written - document-level comments attach to the first entry or section); TrailingComments on an object are emitted after its last entry.
  • Duplicate policies apply at parse. Parse normalizes through IniDocumentOptions (merge / last-wins by default), so the tree never contains duplicates.
  • See also: the line-formats introduction and the INI guide (Pattern 3 - comment-preserving edits with the mutable DOM).

Classes

IniNode

Represents a node in a mutable INI document tree. An INI document is a two-level object-of-objects: the root IniObject maps global keys to IniValue leaves and section names to section IniObject instances, and each section maps key names to IniValue leaves.

IniObject

Represents an object in a mutable INI document tree: an insertion-ordered map of names to nodes. The document root maps global keys to IniValue leaves and section names to section IniObject instances; a section maps key names to IniValue leaves only.

IniValue

Represents a string-valued leaf in a mutable INI document tree.