Initial check in of the LWES DotNet Binding - this is ALPHA code and NOT yet stable.
[lwes-dotnet/github-mirror.git] / Org.Lwes / Config / AbstractConfigurationElementCollection.cs
blobfb9aacddbd13155eafa4184df594e58c0a183c08
1 namespace Org.Lwes.Config
3 using System;
4 using System.Collections.Generic;
5 using System.Configuration;
6 using System.Linq;
7 using System.Text;
9 public abstract class AbstractConfigurationElementCollection<TElement, TKey> : ConfigurationElementCollection
10 where TElement : ConfigurationElement, new()
12 #region Constructors
14 protected AbstractConfigurationElementCollection()
18 protected AbstractConfigurationElementCollection(string addElmName
19 , string clearElmName
20 , string removeElmName)
22 base.AddElementName = addElmName;
23 base.ClearElementName = clearElmName;
24 base.RemoveElementName = removeElmName;
27 #endregion Constructors
29 #region Properties
31 public override ConfigurationElementCollectionType CollectionType
33 get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
36 public new int Count
38 get { return base.Count; }
41 #endregion Properties
43 #region Indexers
45 public TElement this[int index]
47 get { return (TElement)BaseGet(index); }
48 set
50 if (BaseGet(index) != null)
52 BaseRemoveAt(index);
54 BaseAdd(index, value);
58 public TElement this[TKey key]
60 get { return (TElement)BaseGet(key); }
63 #endregion Indexers
65 #region Methods
67 public void Add(TElement item)
69 BaseAdd(item);
72 public void Clear()
74 BaseClear();
77 public int IndexOf(TElement item)
79 return BaseIndexOf(item);
82 public void Remove(TElement item)
84 BaseRemove(GetElementKey(item));
87 public void Remove(TKey key)
89 BaseRemove(key);
92 public void RemoveAt(int index)
94 BaseRemoveAt(index);
97 protected override void BaseAdd(ConfigurationElement element)
99 BaseAdd(element, false);
102 protected override ConfigurationElement CreateNewElement()
104 return new TElement();
107 protected override object GetElementKey(ConfigurationElement element)
109 return PerformGetElementKey((TElement)element);
112 protected abstract TKey PerformGetElementKey(TElement element);
114 #endregion Methods