Bodu.Text.Ini.Document Namespace
- Package
-
Bodu.Text.Ini 1.0.0
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
- IniDocument - the disposable owner:
Parse(fromstringor UTF-8 bytes, with optional IniReaderOptions and IniDocumentOptions) andRootElement. - IniElement - the cursor:
ValueKind(a IniValueKind),GetString,GetProperty/TryGetProperty, andEnumerateObject. - IniElement.ObjectEnumerator - the struct enumerator returned by
EnumerateObject. - IniProperty - a
Name/Valuepair yielded byEnumerateObject.
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
Stringelement; a section is anObject. 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'sJsonDocument. 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'sJsonElement.
- 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.