Table of Contents

Bodu.Text.Ini.Document Namespace

Package

Bodu.Text.Ini.Document

Purpose

Bodu.Text.Ini.Document is the read-only document object model of Bodu.Text.Ini, shaped after System.Text.Json's JsonDocument / JsonElement. A parse produces a disposable IniDocument over the normalized object-of-objects shape - global keys hoisted onto the root, sections as nested objects, duplicates resolved by the IniDocumentOptions policies; each IniElement is a lightweight struct cursor. It is trivia-free: prefer it over the mutable Bodu.Text.Ini.Nodes tier when you only need to query.

Key types

Example

using Bodu.Text.Ini.Document;

using IniDocument document = IniDocument.Parse("timeout=30\n[server]\nhost=localhost\nport=8080\n");

string timeout = document.RootElement.GetProperty("timeout").GetString();   // global key
IniElement server = document.RootElement.GetProperty("server");
foreach (IniProperty entry in server.EnumerateObject())
    Console.WriteLine($"{entry.Name}={entry.Value.GetString()}");

Notes

  • Lifetime. Elements are only valid while their document is undisposed.
  • String-only values. Every entry is a String element; a section is an Object. Convert numbers yourself or bind through the IniSerializer.
  • Comments are dropped. Use the IniNode DOM when comments must survive a rewrite.
  • See also: the line-formats introduction and the INI guide (Pattern 1 - query a document).

Classes

IniDocument

Provides a read-only, pre-parsed view over an INI document, shaped after System.Text.Json's JsonDocument. The document is the normalized two-level object-of-objects: the root object exposes hoisted global keys as string properties and sections as object properties. Comment trivia is not retained.

Structs

IniElement

Represents a single element within an IniDocument - the root object, a section object, or a string value - shaped after System.Text.Json's JsonElement.

IniElement.ObjectEnumerator

Enumerates the properties of an IniElement object.

IniProperty

Represents a single name/value property of an IniElement object - a global key, a section, or a section entry.