-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParameterConfigurationElementCollection.cs
77 lines (67 loc) · 2.3 KB
/
ParameterConfigurationElementCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Configuration;
namespace Mariasek.WinSettings
{
public class ParameterConfigurationElementCollection : ConfigurationElementCollection
{
private const string _ElementName = "parameter";
protected override ConfigurationElement CreateNewElement()
{
return new ParameterConfigurationElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ParameterConfigurationElement)element).Name;
}
public override ConfigurationElementCollectionType CollectionType
{
get { return ConfigurationElementCollectionType.BasicMap; }
}
protected override string ElementName
{
get { return _ElementName; }
}
protected override bool IsElementName(string elementName)
{
if (string.IsNullOrWhiteSpace(elementName) || elementName != _ElementName)
return false;
return true;
}
//public ParameterConfigurationElement this[int index]
//{
// get { return (ParameterConfigurationElement)BaseGet(index); }
// set
// {
// if (BaseGet(index) != null)
// BaseRemoveAt(index);
// BaseAdd(index, value);
// }
//}
public ParameterConfigurationElement this[string key]
{
get { return (ParameterConfigurationElement)BaseGet(key); }
set
{
var index = -1; //append by default
var tempElement = (ParameterConfigurationElement)BaseGet(key);
if (tempElement != null)
{
index = BaseIndexOf(tempElement);
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}
public void Add(string key, string value)
{
BaseAdd(-1, new ParameterConfigurationElement
{
Name = key,
Value = value
});
}
//public string[] AllKeys
//{
// get { return BaseGetAllKeys().Select(i => (string)i).ToArray(); }
//}
}
}