Skip to content

Commit 1b41d88

Browse files
committed
A little polish after the recent commit-a-palooza.
1 parent ee6699e commit 1b41d88

2 files changed

Lines changed: 36 additions & 24 deletions

File tree

README.md

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -396,32 +396,44 @@ public class CustomConfigBuilder : KeyValueConfigBuilder
396396
{
397397
public override void Initialize(string name, NameValueCollection config)
398398
{
399-
// Use this initializer for things that must be read from 'config' immediately upon creation.
400-
// AppSettings parameter substitution is not available at this point.
401-
}
399+
// Use this initializer for things that must be read from 'config' immediately upon creation.
400+
// AppSettings parameter substitution is not available at this point.
401+
// Try using LazyInitialize(string, NameValueCollection) instead when possible.
402+
}
402403

403404
protected override void LazyInitialize(string name, NameValueCollection config)
404405
{
405-
// Use this for things that don't need to be initialized until just before
406-
// config values are retrieved.
407-
// Be sure to begin with 'base.LazyInitialize(name, config)'. AppSettings
408-
// parameter substitution via 'UpdateConfigSettingWithAppSettings(parameterName)'
409-
// will be available after that call.
410-
}
411-
412-
public override bool ValidateKey(string key)
413-
{
414-
// A no-op by default. If your backing storage cannot handle certain characters, this is a one-stop
415-
// place for screening key names. It is particularly helpful in `Strict` and `Expand` modes where
416-
// key names for lookup are taken from *.config files and could potentially contain invalid
417-
// characters that cause exceptions in the backing config store.
418-
}
419-
420-
public override string UpdateKey(string rawKey)
421-
{
422-
// Just before replacing retrieved values in a config section, this method gets called.
423-
// 'AzureKeyVaultConfigBuilder' uses this override to strip version tags from keys.
424-
}
406+
// Use this for things that don't need to be initialized until just before
407+
// config values are retrieved.
408+
// Be sure to begin with 'base.LazyInitialize(name, config)'. AppSettings
409+
// parameter substitution via 'UpdateConfigSettingWithAppSettings(parameterName)'
410+
// will be available after that call.
411+
}
412+
413+
public override bool MapKey(string key)
414+
{
415+
// If you know the format of the key pulled from *.config files is going to be invalid, but you
416+
// are able to translate the bad format to a known good format to get a value from your
417+
// config source, use this method.
418+
// Ex) AppSettings are commonly named things like "area:feature", but the ':' is not a legal
419+
// character for key names in Azure Key Vault. MapKey() can help translate the ':' to a
420+
// '-' in this case, which will allow the ability to look up a config value for this appSetting
421+
// in Key Vault, even though it's original key name is not valid in Key Vault.
422+
}
423+
424+
public override bool ValidateKey(string key)
425+
{
426+
// A no-op by default. If your backing storage cannot handle certain characters, this is a one-stop
427+
// place for screening key names. It is particularly helpful in `Strict` and `Expand` modes where
428+
// key names for lookup are taken from *.config files and could potentially contain invalid
429+
// characters that cause exceptions in the backing config store.
430+
}
431+
432+
public override string UpdateKey(string rawKey)
433+
{
434+
// Just before replacing retrieved values in a config section, this method gets called.
435+
// 'AzureKeyVaultConfigBuilder' uses this override to strip version tags from keys.
436+
}
425437
}
426438
```
427439

test/Microsoft.Configuration.ConfigurationBuilders.Test/BaseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void BaseParameters_TokenPattern()
119119
// Default string. (Not null)
120120
var builder = new FakeConfigBuilder();
121121
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
122-
Assert.Equal(@"\$\{(\w+)\}", builder.TokenPattern);
122+
Assert.Equal(@"\$\{(\w[\w-_$@#+,.:~]*)\}", builder.TokenPattern);
123123

124124
// TokenPattern, case preserved
125125
builder = new FakeConfigBuilder();

0 commit comments

Comments
 (0)