TomlConfigurationProvider Class
Definition
- Namespace
- Bodu.Extensions.Configuration.Text
- Assembly
- Bodu.Extensions.Configuration.Text.dll
- Package
- Bodu.Extensions.Configuration.Text 1.0.0
A read-only IConfigurationProvider that consumes TOML through the Bodu.Text.Toml read-only
document model and flattens it into the colon-delimited configuration key model. Because the provider exposes no
mutation surface, Set(string, string?) is rejected.
public sealed class TomlConfigurationProvider : IConfigurationProvider
- Inheritance
-
TomlConfigurationProvider
- Implements
- Inherited Members
- Extension Methods
Remarks
The provider implements IConfigurationProvider directly rather than deriving from ConfigurationProvider: omitting the mutable base keeps the configuration bridge on the read-only half of the contract, so configuration loaded from TOML cannot be mutated back through the provider.
// Built by TomlConfigurationSource; flattens TOML tables into
// colon-separated configuration keys.
IConfiguration configuration = new ConfigurationBuilder()
.AddTomlFile("appsettings.toml")
.Build();
var level = configuration["logging:level"];
Constructors
TomlConfigurationProvider(TomlConfigurationSource)
Initializes a new instance of the TomlConfigurationProvider class backed by the supplied source.
public TomlConfigurationProvider(TomlConfigurationSource source)
Parameters
sourceTomlConfigurationSourceThe source that produced this provider.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.
Methods
GetChildKeys(IEnumerable<string>, string?)
Returns the immediate child keys beneath parentPath, merged with
earlierKeys.
public IEnumerable<string> GetChildKeys(IEnumerable<string> earlierKeys, string? parentPath)
Parameters
earlierKeysIEnumerable<string>Keys contributed by earlier providers.
parentPathstringThe parent key path, or null for the root.
Returns
- IEnumerable<string>
The distinct child key segments in configuration order.
GetReloadToken()
Returns the change token for this provider. The provider does not reload, so the token never fires.
public IChangeToken GetReloadToken()
Returns
- IChangeToken
A non-firing IChangeToken.
Load()
Loads (and flattens) the TOML source into the configuration data map.
public void Load()
Exceptions
- TomlFormatException
Thrown when the source is not a valid TOML document.
- FileNotFoundException
Thrown when the configured file is absent and the source is not optional.
Set(string, string?)
Rejected: the TOML configuration provider is read-only.
public void Set(string key, string? value)
Parameters
Exceptions
- NotSupportedException
Always thrown, because the provider does not permit mutation.
TryGet(string, out string?)
Attempts to retrieve the configuration value for key.
public bool TryGet(string key, out string? value)
Parameters
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |