BencodeConfigurationProvider 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 Bencode through the Bodu.Text.Bencode
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 BencodeConfigurationProvider : IConfigurationProvider
- Inheritance
-
BencodeConfigurationProvider
- 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 Bencode cannot be mutated back through the provider.
// Built by BencodeConfigurationSource; flattens Bencode dictionaries into
// colon-separated configuration keys.
IConfiguration configuration = new ConfigurationBuilder()
.AddBencodeFile("appsettings.bencode")
.Build();
var level = configuration["logging:level"];
Constructors
BencodeConfigurationProvider(BencodeConfigurationSource)
Initializes a new instance of the BencodeConfigurationProvider class backed by the supplied source.
public BencodeConfigurationProvider(BencodeConfigurationSource source)
Parameters
sourceBencodeConfigurationSourceThe 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 Bencode source into the configuration data map.
public void Load()
Exceptions
- BencodeFormatException
Thrown when the source is not a valid Bencode document.
- FormatException
Thrown when the document root is not a dictionary, or when two keys collide after case-insensitive flattening.
- FileNotFoundException
Thrown when the configured file is absent and the source is not optional.
Set(string, string?)
Rejected: the Bencode 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 |