Added initial documentation tree using doxygen. More tweaks on the license text ensur...
[lwes-dotnet/github-mirror.git] / Org.Lwes / Config / AbstractConfigurationElementCollection.cs
blob07a718f6ef9739ed97ac87d716c7b528f9703eab
1 //
2 // This file is part of the LWES .NET Binding (LWES.net)
3 //
4 // COPYRIGHT© 2009, Phillip Clark (cerebralkungfu[at*g mail[dot*com)
5 // original .NET implementation
6 //
7 // LWES.net is free software: you can redistribute it and/or modify
8 // it under the terms of the Lesser GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // LWES.net is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // Lesser GNU General Public License for more details.
17 // You should have received a copy of the Lesser GNU General Public License
18 // along with LWES.net. If not, see <http://www.gnu.org/licenses/>.
20 namespace Org.Lwes.Config
22 using System.Configuration;
24 /// <summary>
25 /// Base class for configuration element collections.
26 /// </summary>
27 /// <typeparam name="TElement">Element type</typeparam>
28 /// <typeparam name="TKey">Key type</typeparam>
29 public abstract class AbstractConfigurationElementCollection<TElement, TKey> : ConfigurationElementCollection
30 where TElement : ConfigurationElement, new()
32 #region Constructors
34 /// <summary>
35 /// Creates a new instance.
36 /// </summary>
37 protected AbstractConfigurationElementCollection()
41 /// <summary>
42 /// Creates a new instance.
43 /// </summary>
44 /// <param name="addElmName">name used to add an element to the collection (default is 'add')</param>
45 /// <param name="clearElmName">name used when clearing elements from the collection (default is 'clear')</param>
46 /// <param name="removeElmName">name used to delete an element from the collection (default is 'remove')</param>
47 protected AbstractConfigurationElementCollection(string addElmName
48 , string clearElmName
49 , string removeElmName)
51 base.AddElementName = addElmName;
52 base.ClearElementName = clearElmName;
53 base.RemoveElementName = removeElmName;
56 #endregion Constructors
58 #region Properties
60 /// <summary>
61 /// CollectionType
62 /// </summary>
63 public override ConfigurationElementCollectionType CollectionType
65 get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
68 /// <summary>
69 /// Number of elements.
70 /// </summary>
71 public new int Count
73 get { return base.Count; }
76 #endregion Properties
78 #region Indexers
80 /// <summary>
81 /// Accesses an element by index.
82 /// </summary>
83 /// <param name="index">element index</param>
84 /// <returns>the element at <paramref name="index"/></returns>
85 public TElement this[int index]
87 get { return (TElement)BaseGet(index); }
88 set
90 if (BaseGet(index) != null)
92 BaseRemoveAt(index);
94 BaseAdd(index, value);
98 /// <summary>
99 /// Accesses a element by key.
100 /// </summary>
101 /// <param name="key">an element's key</param>
102 /// <returns>the element with the given key</returns>
103 public TElement this[TKey key]
105 get { return (TElement)BaseGet(key); }
108 #endregion Indexers
110 #region Methods
112 /// <summary>
113 /// Adds an element.
114 /// </summary>
115 /// <param name="item"></param>
116 public void Add(TElement item)
118 BaseAdd(item);
121 /// <summary>
122 /// Clears the elements.
123 /// </summary>
124 public void Clear()
126 BaseClear();
129 /// <summary>
130 /// Finds the index of an element.
131 /// </summary>
132 /// <param name="item">the element</param>
133 /// <returns>the index of the element</returns>
134 public int IndexOf(TElement item)
136 return BaseIndexOf(item);
139 /// <summary>
140 /// Removes an element.
141 /// </summary>
142 /// <param name="item">the element</param>
143 public void Remove(TElement item)
145 BaseRemove(GetElementKey(item));
148 /// <summary>
149 /// Removes an element by key.
150 /// </summary>
151 /// <param name="key">the element's key</param>
152 public void Remove(TKey key)
154 BaseRemove(key);
157 /// <summary>
158 /// Removes an element at the given index.
159 /// </summary>
160 /// <param name="index">the element's index</param>
161 public void RemoveAt(int index)
163 BaseRemoveAt(index);
166 /// <summary>
167 /// Creates a new element of type TElement.
168 /// </summary>
169 /// <returns></returns>
170 protected override ConfigurationElement CreateNewElement()
172 return new TElement();
175 /// <summary>
176 /// Gets the element's key.
177 /// </summary>
178 /// <param name="element">the element</param>
179 /// <returns>the element's key</returns>
180 protected override object GetElementKey(ConfigurationElement element)
182 return PerformGetElementKey((TElement)element);
185 /// <summary>
186 /// Abstract method; gets the element's key.
187 /// </summary>
188 /// <param name="element">the element</param>
189 /// <returns>the element's key</returns>
190 protected abstract TKey PerformGetElementKey(TElement element);
192 #endregion Methods