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
streamStreamThe stream to read from. Must support reading.
optionsConfigurationParseOptionsThe parse options to apply, or null for the defaults.
encodingEncodingThe encoding to use when the stream lacks a byte order mark, or null to use the parse options' default encoding.
leaveOpenboolWhen true, the stream remains open after parsing.
Returns
- ConfigurationDocument
A populated ConfigurationDocument.
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes 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
readerTextReaderThe reader to consume.
optionsConfigurationParseOptionsThe parse options, or null for the defaults.
Returns
- ConfigurationDocument
A populated ConfigurationDocument.
Exceptions
- ArgumentNullException
readeris 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
pathstringThe file path.
Returns
- ConfigurationDocument
A populated ConfigurationDocument.
Exceptions
- ArgumentNullException
pathis null.- ArgumentException
pathis 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
pathstringThe file path.
optionsConfigurationParseOptionsThe parse options, or null for the Bodu defaults.
Returns
- ConfigurationDocument
A populated ConfigurationDocument.
Exceptions
- ArgumentNullException
pathis null.- ArgumentException
pathis empty or whitespace.
Parse(string)
Parses configuration text using the default Bodu profile.
public static ConfigurationDocument Parse(string text)
Parameters
textstringThe configuration text to parse.
Returns
- ConfigurationDocument
A populated ConfigurationDocument.
Exceptions
- ArgumentNullException
textis 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
textstringThe configuration text to parse.
optionsConfigurationParseOptionsThe parse options to apply, or null for the Bodu defaults.
Returns
- ConfigurationDocument
A populated ConfigurationDocument.
Exceptions
- ArgumentNullException
textis 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
textstringThe configuration text to parse.
optionsConfigurationParseOptionsThe parse options to apply, or null for the Bodu defaults.
Returns
- ConfigurationParseResult
The parse result.
Exceptions
- ArgumentNullException
textis 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
documentIniDocumentBaseThe document to save.
streamStreamThe destination stream. Must support writing.
optionsConfigurationWriteOptionsThe write options, or null for the defaults.
leaveOpenboolWhen true, the stream remains open after writing.
Exceptions
- ArgumentNullException
documentorstreamis null.- ArgumentException
streamdoes 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
documentIniDocumentBaseThe document to save.
writerTextWriterThe destination writer.
optionsConfigurationWriteOptionsThe write options, or null for the defaults.
Exceptions
- ArgumentNullException
documentorwriteris 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
documentIniDocumentBaseThe document to save.
pathstringThe destination file path.
optionsConfigurationWriteOptionsThe write options, or null for the defaults.
Exceptions
- ArgumentNullException
documentorpathis null.- ArgumentException
pathis 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
textstringThe text to parse.
documentConfigurationDocumentThe parsed document on success; null on failure.
Returns
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
textstringThe text to parse.
optionsConfigurationParseOptionsThe parse options, or null for the Bodu defaults.
documentConfigurationDocumentThe parsed document on success; null on failure.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |