Bodu.Text.Ini Namespace
- Package
-
Bodu.Text.Ini 1.0.0
Purpose
Bodu.Text.Ini parses and emits INI documents - global keys plus [section] blocks of key=value entries - as a standalone System.Text.Json-shaped library: a typed serializer, a two-reader token surface, a comment-preserving mutable node DOM, and a read-only document DOM. It ships as its own package (also available through the Bodu.Text.Formats umbrella); see also Bodu.Text.Delimited and Bodu.Text.DotEnv. For EditorConfig-style layered configuration, use Bodu.Text.Configuration instead - it carries its own INI model.
Key types
- IniSerializer - static serializer: section POCOs / nested dictionaries ↔ INI text, with the
GlobalSectionNamemapping and the depth-2 gate. - IniSerializerOptions / IniSerializerDefaults - naming policy, duplicate policies, and presets (
Strict= configparser strict mode). - IniDocumentOptions with IniDuplicateSectionBehavior / IniDuplicateKeyBehavior - how repeated sections and keys resolve when the document materializes.
- Utf8IniReader - forward-only
ref structreader over the file as authored (source order, comments included). - IniDocumentReader - normalized cursor over the logical object-of-objects shape (globals hoisted, duplicate sections merged).
- Utf8IniWriter - forward-only
ref structwriter (section headers, entries, comment lines). - IniDocument / IniElement - read-only, trivia-free, disposable document model.
- IniNode / IniObject / IniValue - mutable, comment-preserving DOM for faithful rewrites of human-owned files.
- IniFormatException / IniSerializationException - malformed input / policy violations vs. binding failures.
Example
using Bodu.Text.Ini.Nodes;
IniObject root = IniNode.Parse("[server]\nhost=localhost\nport=8080\n"u8);
root["server"].AsObject()["port"].AsValue().Value = "9090";
byte[] back = root.ToUtf8Bytes(); // comments (had there been any) survive
Notes
- Conservative dialect.
=only; values run literally to end of line (an inline;is content);;and#start full-line comments. - Duplicate handling is a document-model policy. The source-order reader reports the file verbatim;
Merge/LastWins(the defaults) apply when the document materializes. - See also: the line-formats introduction and the INI guide.
Namespaces
Classes
- IniFormatException
Represents an error that occurs when INI data is malformed, such as an unterminated section header, an empty section name, or an entry with no assignment.
- IniSectionAttribute
Marks a partial section POCO for compile-time INI binding: the
Bodu.Text.Formats.Generatorssource generator emits an IIniSectionFactory<TSection> implementation for the type, exposed through a generated staticIniFactoryproperty.
- IniSerializationException
Represents an error that occurs while mapping a .NET object to or from INI with IniSerializer, such as an unsupported root type, a member nested beyond INI's two levels, a missing required key, or a value that cannot be converted to the target type.
- IniSerializer
Provides methods for serializing .NET objects to INI text and deserializing INI text into .NET objects, shaped after
System.Text.Json'sJsonSerializer.
- IniSerializerOptions
Provides configuration for IniSerializer, controlling property naming, case sensitivity, field inclusion, null handling, the global-section mapping, and the duplicate-section/key policies.
Structs
- IniDocumentOptions
Provides configuration for the INI document model, controlling how duplicate sections and duplicate keys are resolved when a document is materialized.
Interfaces
- IIniSectionFactory<TSection>
Provides reflection-free conversion between a section type and its INI key/value representation, consumed by the IniSerializer section overloads.
Enums
- IniDuplicateKeyBehavior
Specifies how the INI document model resolves a key that appears more than once within the same section.
- IniDuplicateSectionBehavior
Specifies how the INI document model resolves a section name that appears more than once.
- IniSerializerDefaults
Specifies a set of default settings an IniSerializerOptions can be initialized from.
- IniTokenType
Enumerates the token kinds a Utf8IniReader reports as it advances through an INI document in source order.
- IniValueKind
Enumerates the value kinds an INI node or element can represent.