[xbuild] Actually delete common files (CopyLocal) during Clean.
[mono.git] / mcs / class / System.Configuration / System.Configuration / ConfigurationSectionGroupCollection.cs
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.
26 //
27 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
28 //
29
30 #if NET_2_0
31 using System;
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Runtime.Serialization;
35
36 namespace System.Configuration {
37
38         [Serializable]
39         public sealed class ConfigurationSectionGroupCollection : NameObjectCollectionBase
40         {
41                 SectionGroupInfo group;
42                 Configuration config;
43                 
44                 internal ConfigurationSectionGroupCollection (Configuration config, SectionGroupInfo group)
45                         : base (StringComparer.Ordinal)
46                 {
47                         this.config = config;
48                         this.group = group;
49                 }
50                 
51                 public override NameObjectCollectionBase.KeysCollection Keys {
52                         get { return group.Groups.Keys; }
53                 }
54
55                 public override int Count {
56                         get { return group.Groups.Count; }
57                 }
58
59                 public ConfigurationSectionGroup this [string name] {
60                         get {
61                                 ConfigurationSectionGroup sec = BaseGet (name) as ConfigurationSectionGroup;
62                                 if (sec == null) {
63                                         SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo;
64                                         if (secData == null) return null;
65                                         sec = config.GetSectionGroupInstance (secData);
66                                         BaseSet (name, sec);
67                                 }
68                                 return sec;
69                         }
70                 }
71
72                 public ConfigurationSectionGroup this [int index] {
73                         get { return this [GetKey (index)]; }
74                 }
75
76                 public void Add (string name, ConfigurationSectionGroup sectionGroup)
77                 {
78                         config.CreateSectionGroup (group, name, sectionGroup);
79                 }
80
81                 public void Clear ()
82                 {
83                         if (group.Groups != null) {
84                                 foreach (ConfigInfo data in group.Groups)
85                                         config.RemoveConfigInfo (data);
86                         }
87                 }
88
89                 public void CopyTo (ConfigurationSectionGroup [] array, int index)
90                 {
91                         for (int n=0; n<group.Groups.Count; n++)
92                                 array [n + index] = this [n];
93                 }
94
95                 public ConfigurationSectionGroup Get (int index)
96                 {
97                         return this [index];
98                 }
99
100                 public ConfigurationSectionGroup Get (string name)
101                 {
102                         return this [name];
103                 }
104
105                 public override IEnumerator GetEnumerator ()
106                 {
107                         return group.Groups.AllKeys.GetEnumerator ();
108                 }
109
110                 public string GetKey (int index)
111                 {
112                         return group.Groups.GetKey (index);
113                 }
114
115                 public void Remove (string name)
116                 {
117                         SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo;
118                         if (secData != null)
119                                 config.RemoveConfigInfo (secData);
120                 }
121                 
122                 public void RemoveAt (int index)
123                 {
124                         SectionGroupInfo secData = group.Groups [index] as SectionGroupInfo;
125                         config.RemoveConfigInfo (secData);
126                 }
127
128                 [MonoTODO]
129                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
130                 {
131                         throw new NotImplementedException ();
132                 }
133         }
134 }
135 #endif