comparison Chronosv2/source/Configuration/GenericElementCollection.cs @ 10:443821e55f06

Initial cleaned up add from Codeplex files
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 17:25:44 +0700
parents
children 09d18d6e5f40
comparison
equal deleted inserted replaced
9:904a9faadf8b 10:443821e55f06
1 using System.Configuration;
2
3 namespace Chronos.Configuration
4 {
5 /// <summary>
6 /// http://utahdnug.org/blogs/josh/archive/2007/08/21/generic-configurationelementcollection.aspx
7 /// </summary>
8 /// <typeparam name="K"></typeparam>
9 /// <typeparam name="V"></typeparam>
10 public abstract class GenericElementCollection<K, V>
11 : ConfigurationElementCollection where V : ConfigurationElement, new()
12 {
13 #region · Properties ·
14
15 /// <summary>
16 /// Gets the type of the <see cref="T:System.Configuration.ConfigurationElementCollection"/>.
17 /// </summary>
18 /// <value></value>
19 /// <returns>
20 /// The <see cref="T:System.Configuration.ConfigurationElementCollectionType"/> of this collection.
21 /// </returns>
22 public abstract override ConfigurationElementCollectionType CollectionType
23 {
24 get;
25 }
26
27 /// <summary>
28 /// Gets the name used to identify this collection of elements in the configuration file when overridden in a derived class.
29 /// </summary>
30 /// <value></value>
31 /// <returns>
32 /// The name of the collection; otherwise, an empty string. The default is an empty string.
33 /// </returns>
34 protected abstract override string ElementName
35 {
36 get;
37 }
38
39 #endregion
40
41 #region · Indexers ·
42
43 /// <summary>
44 /// Gets the <see cref="ConfigurationElement"/> with the specified key.
45 /// </summary>
46 /// <value></value>
47 public V this[K key]
48 {
49 get { return (V)BaseGet(key); }
50 }
51
52 /// <summary>
53 /// Gets the <see cref="ConfigurationElement"/> at the specified index.
54 /// </summary>
55 /// <value></value>
56 public V this[int index]
57 {
58 get { return (V)BaseGet(index); }
59 }
60
61 #endregion
62
63 #region · Constructors ·
64
65 /// <summary>
66 /// Initializes a new instance of the <see cref="GenericElementCollection&lt;K, V&gt;"/> class.
67 /// </summary>
68 public GenericElementCollection()
69 {
70 }
71
72 #endregion
73
74 #region · Methods ·
75
76 /// <summary>
77 /// Adds the specified path.
78 /// </summary>
79 /// <param name="path">The path.</param>
80 public void Add(V path)
81 {
82 BaseAdd(path);
83 }
84
85 /// <summary>
86 /// Removes the specified key.
87 /// </summary>
88 /// <param name="key">The key.</param>
89 public void Remove(K key)
90 {
91 BaseRemove(key);
92 }
93
94 #endregion
95
96 #region · Overriden Methods ·
97
98 /// <summary>
99 /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
100 /// </summary>
101 /// <returns>
102 /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
103 /// </returns>
104 protected override ConfigurationElement CreateNewElement()
105 {
106 return new V();
107 }
108
109 /// <summary>
110 /// Gets the element key for a specified configuration element when overridden in a derived class.
111 /// </summary>
112 /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
113 /// <returns>
114 /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
115 /// </returns>
116 protected override object GetElementKey(ConfigurationElement element)
117 {
118 return GetElementKey((V)element);
119 }
120
121 #endregion
122
123 #region · Protected Abstract Methods ·
124
125 /// <summary>
126 /// Gets the element key.
127 /// </summary>
128 /// <param name="element">The element.</param>
129 /// <returns></returns>
130 protected abstract K GetElementKey(V element);
131
132 #endregion
133 }
134 }