1: using System.Configuration;
2:
3: namespace CustomConfigApp
4: {
5: public class ConfigHelper : ConfigurationSection
6: {
7: /// <summary>
8: /// The value of the property here "Folders" needs to match that of the config file section
9: /// </summary>
10: [ConfigurationProperty("FilterKeys")]
11: public FilterHashKeyCollection HashKeys
12: {
13: get { return ((FilterHashKeyCollection)(base["FilterKeys"])); }
14: }
15: }
16:
17: /// <summary>
18: /// The collection class that will store the list of each element/item that
19: /// is returned back from the configuration manager.
20: /// </summary>
21: [ConfigurationCollection(typeof(FilterHashElement))]
22: public class FilterHashKeyCollection : ConfigurationElementCollection
23: {
24: protected override ConfigurationElement CreateNewElement()
25: {
26: return new FilterHashElement();
27: }
28:
29: protected override object GetElementKey(ConfigurationElement element)
30: {
31: return ((FilterHashElement)(element)).Key;
32: }
33:
34: public FilterHashElement this[int idx]
35: {
36: get
37: {
38: return (FilterHashElement)BaseGet(idx);
39: }
40: }
41: }
42:
43: /// <summary>
44: /// The class that holds onto each element returned by the configuration manager.
45: /// </summary>
46: public class FilterHashElement : ConfigurationElement
47: {
48: [ConfigurationProperty("key", DefaultValue = "", IsKey = true, IsRequired = true)]
49: public string Key
50: {
51: get
52: {
53: return ((string)(base["key"]));
54: }
55: set
56: {
57: base["key"] = value;
58: }
59: }
60:
61: [ConfigurationProperty("value", DefaultValue = "", IsKey = false, IsRequired = false)]
62: public string Value
63: {
64: get
65: {
66: return ((string)(base["value"]));
67: }
68: set
69: {
70: base["value"] = value;
71: }
72: }
73: }
74: }