public override ConfigurationSection ProcessConfigurationSection(ConfigurationSection configSection) { // Expand mode only works on the raw string input if (Mode == KeyValueMode.Expand) { return(configSection); } // See if we know how to process this section ISectionHandler handler = SectionHandlersSection.GetSectionHandler(configSection); if (handler == null) { return(configSection); } if (configSection.SectionInformation?.SectionName == "appSettings") { _appSettings = configSection as AppSettingsSection; } // Strict Mode. Only replace existing key/values. if (Mode == KeyValueMode.Strict) { foreach (var configItem in handler) { // Presumably, UpdateKey will preserve casing appropriately, so newKey is cased as expected. string newKey = UpdateKey(configItem.Key); string newValue = GetValueInternal(configItem.Key); if (newValue != null) { handler.InsertOrUpdate(newKey, newValue, configItem.Key, configItem.Value); } } } // Greedy Mode. Insert all key/values. else if (Mode == KeyValueMode.Greedy) { EnsureGreedyInitialized(); foreach (KeyValuePair <string, string> kvp in _cachedValues) { if (kvp.Value != null) { // Here, kvp.Key is not from the config file, so it might not be correctly cased. Get the correct casing for UpdateKey. string oldKey = TrimPrefix(kvp.Key); string newKey = UpdateKey(handler.TryGetOriginalCase(oldKey)); handler.InsertOrUpdate(newKey, kvp.Value, oldKey); } } } return(configSection); }
public override ConfigurationSection ProcessConfigurationSection(ConfigurationSection configSection) { // Expand mode only works on the raw string input if (Mode == KeyValueMode.Expand) { return(configSection); } // See if we know how to process this section ISectionHandler handler = SectionHandlersSection.GetSectionHandler(configSection); if (handler == null) { return(configSection); } _appSettings = configSection as AppSettingsSection; // Strict Mode. Only replace existing key/values. if (Mode == KeyValueMode.Strict) { foreach (var configItem in handler) { string newValue = GetValueInternal(configItem.Key); string newKey = UpdateKey(configItem.Key); if (newValue != null) { handler.InsertOrUpdate(newKey, newValue, configItem.Key, configItem.Value); } } } // Greedy Mode. Insert all key/values. else if (Mode == KeyValueMode.Greedy) { EnsureGreedyInitialized(); foreach (KeyValuePair <string, string> kvp in _cachedValues) { if (kvp.Value != null) { string oldKey = TrimPrefix(kvp.Key); string newKey = UpdateKey(oldKey); handler.InsertOrUpdate(newKey, kvp.Value, oldKey); } } } return(configSection); }