<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0-rc.1.24431.7" />

DictionarySectionHandler

Provides key/value pair configuration information from a configuration section.
using System.Collections; using System.Xml; namespace System.Configuration { public class DictionarySectionHandler : IConfigurationSectionHandler { protected virtual string KeyAttributeName => "key"; protected virtual string ValueAttributeName => "value"; internal virtual bool ValueRequired => false; public virtual object Create(object parent, object context, XmlNode section) { Hashtable hashtable = (parent != null) ? ((Hashtable)((Hashtable)parent).Clone()) : new Hashtable(StringComparer.OrdinalIgnoreCase); HandlerBase.CheckForUnrecognizedAttributes(section); foreach (XmlNode childNode in section.ChildNodes) { if (!HandlerBase.IsIgnorableAlsoCheckForNonElement(childNode)) { if (childNode.Name == "add") { HandlerBase.CheckForChildNodes(childNode); string key = HandlerBase.RemoveRequiredAttribute(childNode, KeyAttributeName); string text = ValueRequired ? HandlerBase.RemoveRequiredAttribute(childNode, ValueAttributeName) : HandlerBase.RemoveAttribute(childNode, ValueAttributeName); HandlerBase.CheckForUnrecognizedAttributes(childNode); hashtable[key] = (text ?? ""); } else if (childNode.Name == "remove") { HandlerBase.CheckForChildNodes(childNode); string key2 = HandlerBase.RemoveRequiredAttribute(childNode, KeyAttributeName); HandlerBase.CheckForUnrecognizedAttributes(childNode); hashtable.Remove(key2); } else if (childNode.Name.Equals("clear")) { HandlerBase.CheckForChildNodes(childNode); HandlerBase.CheckForUnrecognizedAttributes(childNode); hashtable.Clear(); } else { HandlerBase.ThrowUnrecognizedElement(childNode); } } } return hashtable; } } }