KeyValueConfigurationCollection
namespace System.Configuration
{
[ConfigurationCollection(typeof(KeyValueConfigurationElement))]
public class KeyValueConfigurationCollection : ConfigurationElementCollection
{
private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
protected internal override ConfigurationPropertyCollection Properties => s_properties;
protected override bool ThrowOnDuplicate => false;
public new KeyValueConfigurationElement this[string key] {
get {
return (KeyValueConfigurationElement)BaseGet(key);
}
}
public string[] AllKeys => StringUtil.ObjectArrayToStringArray(BaseGetAllKeys());
public KeyValueConfigurationCollection()
: base(StringComparer.OrdinalIgnoreCase)
{
InternalAddToEnd = true;
}
public void Add(KeyValueConfigurationElement keyValue)
{
keyValue.Init();
KeyValueConfigurationElement keyValueConfigurationElement = (KeyValueConfigurationElement)BaseGet(keyValue.Key);
if (keyValueConfigurationElement == null)
BaseAdd(keyValue);
else {
KeyValueConfigurationElement keyValueConfigurationElement2 = keyValueConfigurationElement;
keyValueConfigurationElement2.Value = keyValueConfigurationElement2.Value + "," + keyValue.Value;
int index = BaseIndexOf(keyValueConfigurationElement);
BaseRemoveAt(index);
BaseAdd(index, keyValueConfigurationElement);
}
}
public void Add(string key, string value)
{
KeyValueConfigurationElement keyValue = new KeyValueConfigurationElement(key, value);
Add(keyValue);
}
public void Remove(string key)
{
BaseRemove(key);
}
public void Clear()
{
BaseClear();
}
protected override ConfigurationElement CreateNewElement()
{
return new KeyValueConfigurationElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((KeyValueConfigurationElement)element).Key;
}
}
}