Table of Contents

ConfigurationDocument Class

Definition

Namespace
Bodu.Text.Configuration
Assembly
Bodu.Text.Configuration.dll
Package
Bodu.Text.Configuration 1.0.0
Source
ConfigurationDocument.cs

Represents a parsed Bodu Text Configuration document and provides the profile-aware entry points for parsing, loading, and saving such documents. It inherits the read-only INI model from IniDocumentBase (global section, named sections, lookup) and adds Bodu-specific behaviour - profile presets, inline-comment-mode handling, diagnostic routing, and round-trip support - on top of the shared INI infrastructure.

public sealed class ConfigurationDocument : IniDocumentBase
Inheritance
ConfigurationDocument
Inherited Members
Extension Methods

Examples

// Parse and resolve a configuration file for a specific target path.
ConfigurationDocument doc  = ConfigurationDocument.Parse(text);
ConfigurationView     view = doc.Resolve("src/Foo.cs");
int indent = view.GetInt32("format:indent:size", 4);

// Collect every diagnostic instead of failing on the first issue.
var opts = new ConfigurationParseOptions
{
    Profile        = ConfigurationProfile.Bodu,
    DiagnosticMode = ConfigurationDiagnosticMode.Collect,
};
ConfigurationParseResult result = ConfigurationDocument.ParseWithDiagnostics(text, opts);
foreach (ConfigurationDiagnostic d in result.Diagnostics)
    Console.WriteLine(d);

Remarks

Pair the Parse(string) family with the Resolve(IniDocumentBase, string?, ConfigurationResolveOptions?) extension method to evaluate the document for a specific target path. The document holds the raw, source-faithful model; ConfigurationView holds the resolved, target-specific snapshot consumed by application code.

A ConfigurationDocument exposes only the read surface of IniDocumentBase; it is produced by the configuration reader and is not mutated by application code.

Diagnostic routing is controlled by the supplied ConfigurationParseOptions. In Throw mode a recoverable parse error raises ConfigurationParseException at the first issue; in Collect mode the parser continues, the document's valid portions remain usable, and every diagnostic surfaces on Diagnostics.

Methods

Load(Stream, ConfigurationParseOptions?, Encoding?, bool)

Loads a configuration document from the supplied stream.

public static ConfigurationDocument Load(Stream stream, ConfigurationParseOptions? options = null, Encoding? encoding = null, bool leaveOpen = false)

Parameters

stream Stream

The stream to read from. Must support reading.

options ConfigurationParseOptions

The parse options to apply, or null for the defaults.

encoding Encoding

The encoding to use when the stream lacks a byte order mark, or null to use the parse options' default encoding.

leaveOpen bool

When true, the stream remains open after parsing.

Returns

ConfigurationDocument

A populated ConfigurationDocument.

Exceptions

ArgumentNullException

stream is null.

ArgumentException

stream does not support reading.

Load(TextReader, ConfigurationParseOptions?)

Loads a configuration document from the supplied text reader.

public static ConfigurationDocument Load(TextReader reader, ConfigurationParseOptions? options = null)

Parameters

reader TextReader

The reader to consume.

options ConfigurationParseOptions

The parse options, or null for the defaults.

Returns

ConfigurationDocument

A populated ConfigurationDocument.

Exceptions

ArgumentNullException

reader is null.

Load(string)

Loads a configuration document from the file at path using the default Bodu profile and UTF-8 encoding with BOM detection.

public static ConfigurationDocument Load(string path)

Parameters

path string

The file path.

Returns

ConfigurationDocument

A populated ConfigurationDocument.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty or whitespace.

Load(string, ConfigurationParseOptions?)

Loads a configuration document from the file at path using the supplied options.

public static ConfigurationDocument Load(string path, ConfigurationParseOptions? options)

Parameters

path string

The file path.

options ConfigurationParseOptions

The parse options, or null for the Bodu defaults.

Returns

ConfigurationDocument

A populated ConfigurationDocument.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty or whitespace.

Parse(string)

Parses configuration text using the default Bodu profile.

public static ConfigurationDocument Parse(string text)

Parameters

text string

The configuration text to parse.

Returns

ConfigurationDocument

A populated ConfigurationDocument.

Exceptions

ArgumentNullException

text is null.

ConfigurationParseException

The text could not be parsed.

Parse(string, ConfigurationParseOptions?)

Parses configuration text using the supplied options.

public static ConfigurationDocument Parse(string text, ConfigurationParseOptions? options)

Parameters

text string

The configuration text to parse.

options ConfigurationParseOptions

The parse options to apply, or null for the Bodu defaults.

Returns

ConfigurationDocument

A populated ConfigurationDocument.

Exceptions

ArgumentNullException

text is null.

ConfigurationParseException

The text could not be parsed.

ParseWithDiagnostics(string, ConfigurationParseOptions?)

Parses configuration text and returns the resulting document together with any diagnostics collected during the parse.

public static ConfigurationParseResult ParseWithDiagnostics(string text, ConfigurationParseOptions? options = null)

Parameters

text string

The configuration text to parse.

options ConfigurationParseOptions

The parse options to apply, or null for the Bodu defaults.

Returns

ConfigurationParseResult

The parse result.

Exceptions

ArgumentNullException

text is null.

ConfigurationParseException

The text could not be parsed and DiagnosticMode is Throw.

Save(IniDocumentBase, Stream, ConfigurationWriteOptions?, bool)

Saves document to the supplied stream.

public static void Save(IniDocumentBase document, Stream stream, ConfigurationWriteOptions? options = null, bool leaveOpen = false)

Parameters

document IniDocumentBase

The document to save.

stream Stream

The destination stream. Must support writing.

options ConfigurationWriteOptions

The write options, or null for the defaults.

leaveOpen bool

When true, the stream remains open after writing.

Exceptions

ArgumentNullException

document or stream is null.

ArgumentException

stream does not support writing.

Save(IniDocumentBase, TextWriter, ConfigurationWriteOptions?)

Saves document to the supplied text writer.

public static void Save(IniDocumentBase document, TextWriter writer, ConfigurationWriteOptions? options = null)

Parameters

document IniDocumentBase

The document to save.

writer TextWriter

The destination writer.

options ConfigurationWriteOptions

The write options, or null for the defaults.

Exceptions

ArgumentNullException

document or writer is null.

Save(IniDocumentBase, string, ConfigurationWriteOptions?)

Saves document to the file at path, replacing any existing content.

public static void Save(IniDocumentBase document, string path, ConfigurationWriteOptions? options = null)

Parameters

document IniDocumentBase

The document to save.

path string

The destination file path.

options ConfigurationWriteOptions

The write options, or null for the defaults.

Exceptions

ArgumentNullException

document or path is null.

ArgumentException

path is empty or whitespace.

TryParse(string?, out ConfigurationDocument?)

Attempts to parse configuration text using the default Bodu profile.

public static bool TryParse(string? text, out ConfigurationDocument? document)

Parameters

text string

The text to parse.

document ConfigurationDocument

The parsed document on success; null on failure.

Returns

bool

true on success; otherwise, false.

TryParse(string?, ConfigurationParseOptions?, out ConfigurationDocument?)

Attempts to parse configuration text using the supplied options.

public static bool TryParse(string? text, ConfigurationParseOptions? options, out ConfigurationDocument? document)

Parameters

text string

The text to parse.

options ConfigurationParseOptions

The parse options, or null for the Bodu defaults.

document ConfigurationDocument

The parsed document on success; null on failure.

Returns

bool

true on success; otherwise, false.

Applies to

ProductVersions
.NET8, 10