TextStreamConfigurationSource Class
Definition
- Namespace
- Bodu.Extensions.Configuration.Text
- Assembly
- Bodu.Extensions.Configuration.Text.dll
- Package
- Bodu.Extensions.Configuration.Text 1.0.0
A StreamConfigurationSource that reads a Bodu Text Configuration document from an arbitrary Stream and projects its resolved view into the IConfiguration hierarchy as colon-delimited keys.
public sealed class TextStreamConfigurationSource : StreamConfigurationSource, IConfigurationSource
- Inheritance
-
TextStreamConfigurationSource
- Implements
- Inherited Members
- Extension Methods
Examples
// Test-time configuration from an in-memory string.
const string ConfigText = """
[*]
Logging:Level = Debug
[src/**/*.cs]
format:indent:size = 4
""";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(ConfigText));
IConfigurationRoot root = new ConfigurationBuilder()
.AddTextConfigurationStream(source =>
{
source.Stream = stream;
source.TargetPath = "src/Foo.cs";
})
.Build();
Console.WriteLine(root["Logging:Level"]); // "Debug"
Console.WriteLine(root["format:indent:size"]); // "4"
Remarks
Mirrors the role of JsonStreamConfigurationSource in Microsoft.Extensions.Configuration.Json. Unlike
TextConfigurationSource (which is file-backed and inherits reload-on-change), this source is
one-shot: the stream is parsed once when Build(IConfigurationBuilder) is invoked and no file watcher
is attached. The caller is responsible for the stream's lifetime; the provider does not dispose it.
Use this shape when the configuration text lives somewhere other than the file system - embedded resources, in-memory test inputs, content downloaded from a config service, or content authored by another part of the host process. TargetPath, ParseOptions, and ResolveOptions behave the same way as on the file-backed source.
Constructors
TextStreamConfigurationSource()
public TextStreamConfigurationSource()
Properties
ParseOptions
Gets or sets the parse options applied when the stream is loaded.
public ConfigurationParseOptions? ParseOptions { get; set; }
Property Value
- ConfigurationParseOptions
The parse options, or null for the defaults.
ResolveOptions
Gets or sets the resolve options applied when projecting the document into the configuration view.
public ConfigurationResolveOptions? ResolveOptions { get; set; }
Property Value
- ConfigurationResolveOptions
The resolve options, or null for the defaults.
TargetPath
Gets or sets the path used to evaluate glob-anchored sections during resolution. Defaults to null, in which case only non-anchored matches and preamble values apply.
public string? TargetPath { get; set; }
Property Value
- string
The target path supplied to the resolver.
Methods
Build(IConfigurationBuilder)
Builds the StreamConfigurationProvider for this source.
public override IConfigurationProvider Build(IConfigurationBuilder builder)
Parameters
builderIConfigurationBuilder
Returns
- IConfigurationProvider
An IConfigurationProvider instance.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |