**** Merged from MCS ****
[mono-project.git] / mcs / class / System / System.Configuration / ConfigurationSectionGroupCollection.cs
blobc735954ade61f81d25058fd0d596bc4e5fd38ce0
1 //
2 // System.Configuration.ConfigurationSectionGroupCollection.cs
3 //
4 // Authors:
5 // Duncan Mak (duncan@ximian.com)
6 // Lluis Sanchez Gual (lluis@novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
30 #if NET_2_0 && XML_DEP
31 using System;
32 using System.Collections;
33 using System.Collections.Specialized;
35 namespace System.Configuration {
37 public sealed class ConfigurationSectionGroupCollection : NameObjectCollectionBase
39 SectionGroupInfo group;
40 Configuration config;
42 internal ConfigurationSectionGroupCollection (Configuration config, SectionGroupInfo group)
44 this.config = config;
45 this.group = group;
48 public ICollection AllKeys {
49 get { return group.Groups.AllKeys; }
52 public override int Count {
53 get { return group.Groups.Count; }
56 public ConfigurationSectionGroup this [string name] {
57 get {
58 ConfigurationSectionGroup sec = BaseGet (name) as ConfigurationSectionGroup;
59 if (sec == null) {
60 SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo;
61 if (secData == null) return null;
62 sec = config.GetSectionGroupInstance (secData);
63 BaseSet (name, sec);
65 return sec;
69 public ConfigurationSectionGroup this [int index] {
70 get { return this [GetKey (index)]; }
73 public void Add (string name, ConfigurationSectionGroup sectionGroup)
75 config.CreateSectionGroup (group, name, sectionGroup);
78 public void Clear ()
80 if (group.Groups != null) {
81 foreach (ConfigInfo data in group.Groups)
82 config.RemoveConfigInfo (data);
86 public void CopyTo (ConfigurationSectionGroup [] array, int index)
88 for (int n=0; n<group.Groups.Count; n++)
89 array [n + index] = this [n];
92 public ConfigurationSectionGroup Get (int index)
94 return this [index];
97 public ConfigurationSectionGroup Get (string name)
99 return this [name];
102 public override IEnumerator GetEnumerator ()
104 return group.Groups.AllKeys.GetEnumerator ();
107 public string GetKey (int index)
109 return group.Groups.GetKey (index);
112 public void Remove (string name)
114 SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo;
115 if (secData != null)
116 config.RemoveConfigInfo (secData);
119 public void RemoveAt (int index)
121 SectionGroupInfo secData = group.Groups [index] as SectionGroupInfo;
122 config.RemoveConfigInfo (secData);
126 #endif