Changes approved via private email from Marek Habersack <mhabersack@novell.com> on...
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / ProfileGroupSettingsCollection.cs
1 //
2 // System.Web.Configuration.ProfileGroupSettingsCollection
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.Configuration;
35
36 namespace System.Web.Configuration
37 {
38         [ConfigurationCollection (typeof (ProfileGroupSettings), AddItemName="group", CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
39         public sealed class ProfileGroupSettingsCollection : ConfigurationElementCollection
40         {
41                 static ConfigurationPropertyCollection properties;
42                 
43                 static ProfileGroupSettingsCollection ()
44                 {
45                         properties = new ConfigurationPropertyCollection ();
46                 }
47                 
48                 public void Add (ProfileGroupSettings group)
49                 {
50                         BaseAdd (group);
51                 }
52
53                 public string[] AllKeys {
54                         get {
55                                 string[] ret = new string [Count];
56                                 for (int i = 0; i < Count; i++)
57                                         ret [i] = this [i].Name;
58
59                                 return ret;
60                         }
61                 }
62
63                 // Why override?
64                 protected override bool IsModified ()
65                 {
66                         return base.IsModified ();
67                 }
68
69                 // Why override?
70                 protected override void ResetModified ()
71                 {
72                         base.ResetModified ();
73                 }
74                 
75                 public void Clear ()
76                 {
77                         BaseClear ();
78                 }
79
80                 protected override ConfigurationElement CreateNewElement ()
81                 {
82                         return new ProfileGroupSettings ();
83                 }
84
85                 public ProfileGroupSettings Get (int index)
86                 {
87                         return (ProfileGroupSettings) BaseGet (index);
88                 }
89
90                 public ProfileGroupSettings Get (string name)
91                 {
92                         return (ProfileGroupSettings) BaseGet (name);
93                 }
94
95                 protected override object GetElementKey (ConfigurationElement element)
96                 {
97                         return ((ProfileGroupSettings) element).Name;
98                 }
99
100                 public string GetKey (int index)
101                 {
102                         return (string)BaseGetKey (index);
103                 }
104
105                 public int IndexOf (ProfileGroupSettings group)
106                 {
107                         return BaseIndexOf (group);
108                 }
109
110                 public void Remove (string name)
111                 {
112                         BaseRemove (name);
113                 }
114
115                 public void RemoveAt (int index)
116                 {
117                         BaseRemoveAt (index);
118                 }
119
120                 public void Set (ProfileGroupSettings group)
121                 {
122                         ProfileGroupSettings existing = Get (group.Name);
123
124                         if (existing == null) {
125                                 Add (group);
126                         }
127                         else {
128                                 int index = BaseIndexOf (existing);
129                                 RemoveAt (index);
130                                 BaseAdd (index, group);
131                         }
132                 }
133
134                 public ProfileGroupSettings this[int index] {
135                         get { return Get (index); }
136                         set { if (BaseGet (index) != null) BaseRemoveAt (index); BaseAdd (index, value); }
137                 }
138
139                 public new ProfileGroupSettings this[string name] {
140                         get { return (ProfileGroupSettings) BaseGet (name); }
141                 }
142
143                 protected override ConfigurationPropertyCollection Properties {
144                         get { return properties; }
145                 }
146                 
147                 internal void ResetInternal (ConfigurationElement parentElement)
148                 {
149                         Reset (parentElement);
150                 }
151
152                 internal void AddNewSettings (ProfileGroupSettings newSettings)
153                 {
154                         // allow overriding - no exception should be thrown
155                         BaseAdd (newSettings, false);
156                 }
157         }
158
159 }
160
161 #endif