ConfigurationExtensions Class
Definition
- Namespace
- Bodu.Text.Configuration
- Assembly
- Bodu.Text.Configuration.dll
- Package
- Bodu.Text.Configuration 1.3.0
Extension methods that layer Bodu Text Configuration behavior (path-aware resolution and dotted-to-colon key mapping) onto the underlying IniDocumentBase and IniEntry primitives.
public static class ConfigurationExtensions
- Inheritance
-
ConfigurationExtensions
- Inherited Members
Remarks
The Bodu Text Configuration model is intentionally layered on top of its raw INI document primitives rather than replacing them: an IniDocumentBase remains the source-faithful in-memory representation, and these extension methods add the configuration-specific behavior - target-path resolution and dotted-to-colon key normalization - that turns that raw document into the resolved snapshot consumed by application code.
The primary entry point is Resolve(IniDocumentBase, string?, ConfigurationResolveOptions?), which produces a ConfigurationView for a supplied target path. Pair it with Parse(string) at the start of the pipeline and with the typed accessors on ConfigurationView at its end.
ConfigurationDocument document = ConfigurationDocument.Parse("""
root = true
[*]
indent_size = 4
[src/**.cs]
indent_size = 8
""");
// Sections whose glob matches the target path apply, later sections winning.
ConfigurationView view = document.Resolve("src/App/Program.cs");
var indent = view.GetInt32("indent_size"); // 8
Methods
ConfigurationPath(IniEntry, ConfigurationKeyOptions?)
Computes the configuration path for an entry's raw key using the supplied key options: colon-delimited, or the key as written under Identity. Mirrors Parse(string, ConfigurationKeyOptions?) and exposes the resulting Path.
public static string ConfigurationPath(this IniEntry entry, ConfigurationKeyOptions? options = null)
Parameters
entryIniEntryThe entry whose key should be transformed.
optionsConfigurationKeyOptionsThe key options, or null for the defaults.
Returns
- string
The configuration path of the entry's key.
Exceptions
- ArgumentNullException
entryis null.
Resolve(IniDocumentBase, string?)
Projects the document into a resolved ConfigurationView for the supplied target path using the default Bodu resolve options.
public static ConfigurationView Resolve(this IniDocumentBase document, string? targetPath = null)
Parameters
documentIniDocumentBaseThe document to resolve.
targetPathstringThe path the resolved view is evaluated for, or null.
Returns
- ConfigurationView
A populated ConfigurationView.
Remarks
A document loaded with Load(string, ConfigurationParseOptions?) is rooted at the directory of its file, so a target path under that directory is matched relative to it.
Exceptions
- ArgumentNullException
documentis null.- ConfigurationParseException
targetPathis not empty and the name of a section is not a valid glob: an unbalanced bracket or brace, braces nested too deeply, a numeric range too large, or a pattern too long (see Compile(string, StringComparison)).
Resolve(IniDocumentBase, string?, ConfigurationResolveOptions?)
Projects the document into a resolved ConfigurationView for the supplied target path using the supplied options.
public static ConfigurationView Resolve(this IniDocumentBase document, string? targetPath, ConfigurationResolveOptions? options)
Parameters
documentIniDocumentBaseThe document to resolve.
targetPathstringThe path the resolved view is evaluated for, or null.
optionsConfigurationResolveOptionsThe resolve options, or null for the Bodu defaults.
Returns
- ConfigurationView
A populated ConfigurationView.
Remarks
When options sets no PathRoot, a document loaded
with Load(string, ConfigurationParseOptions?) is rooted at the directory of
its file, so a target path under that directory is matched relative to it.
Exceptions
- ArgumentNullException
documentis null.- InvalidOperationException
targetPathis null,optionsselects Throw, and no root is known:optionssets no PathRoot and the document was not loaded from a file.- ConfigurationParseException
targetPathis not empty and the name of a section is not a valid glob: an unbalanced bracket or brace, braces nested too deeply, a numeric range too large, or a pattern too long (see Compile(string, StringComparison)).
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |