1using System;
2using System.Configuration;
3
4namespace HelpersDotNet.Configuration
5{
6 public abstract class ConfigurationElementCollectionBase<T> :
7 ConfigurationElementCollection where T : ConfigurationElement
8 {
9 public override ConfigurationElementCollectionType CollectionType
10 {
11 get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
12 }
13
14 public T this[int index]
15 {
16 get { return (T)base.BaseGet(index); }
17 set
18 {
19 if (base.BaseGet(index) != null)
20 base.BaseRemoveAt(index);
21
22 base.BaseAdd(index, value);
23 }
24 }
25
26 new public T this[string key]
27 {
28 get { return (T)base.BaseGet(key); }
29 }
30
31 public void Add(T element)
32 {
33 base.BaseAdd(element);
34 }
35
36 public void Clear()
37 {
38 base.BaseClear();
39 }
40
41 public bool Contains(string key)
42 {
43 return base.BaseGet(key) != null;
44 }
45
46 protected override ConfigurationElement CreateNewElement()
47 {
48 return Activator.CreateInstance<T>();
49 }
50
51 public void Remove(string key)
52 {
53 base.BaseRemove(key);
54 }
55
56 public void RemoveAt(int index)
57 {
58 base.BaseRemoveAt(index);
59 }
60 }
61}