2010-06-30 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / RootProfilePropertySettingsCollection.cs
1 //
2 // System.Web.Configuration.RootProfilePropertySettingsCollection
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 using System.Xml;
36
37 namespace System.Web.Configuration
38 {
39         [ConfigurationCollection (typeof (ProfilePropertySettings), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
40         public sealed class RootProfilePropertySettingsCollection : ProfilePropertySettingsCollection
41         {
42                 static ConfigurationPropertyCollection properties;
43                 ProfileGroupSettingsCollection groupSettings;
44                 
45                 static RootProfilePropertySettingsCollection ()
46                 {
47                         properties = new ConfigurationPropertyCollection ();
48                 }
49
50                 public RootProfilePropertySettingsCollection ()
51                 {
52                         groupSettings = new ProfileGroupSettingsCollection ();
53                 }               
54                 
55                 public override bool Equals (object obj)
56                 {
57                         RootProfilePropertySettingsCollection col = obj as RootProfilePropertySettingsCollection;
58                         if (col == null)
59                                 return false;
60
61                         if (GetType () != col.GetType ())
62                                 return false;
63
64                         if (Count != col.Count)
65                                 return false;
66
67                         for (int n = 0; n < Count; n++) {
68                                 if (!BaseGet (n).Equals (col.BaseGet (n)))
69                                         return false;
70                         }
71                         return true;
72                 }
73
74                 public override int GetHashCode ()
75                 {
76                         int code = 0;
77                         for (int n = 0; n < Count; n++)
78                                 code += BaseGet (n).GetHashCode ();
79                         return code;
80                 }
81
82                 protected override bool AllowClear {
83                         get { return true; }
84                 }
85
86                 // LAMESPEC: this is missing from MSDN but is present in 2.0sp1 version of the
87                 // class.
88                 protected override bool OnDeserializeUnrecognizedElement (string elementName, XmlReader reader)
89                 {
90                         if (elementName == "group") {
91                                 ProfileGroupSettings newSettings = new ProfileGroupSettings ();
92                                 newSettings.DoDeserialize (reader);
93                                 GroupSettings.AddNewSettings (newSettings);
94                                 
95                                 return true;
96                         }
97                         
98                         return base.OnDeserializeUnrecognizedElement (elementName, reader);
99                 }
100
101                 // LAMESPEC: this is missing from MSDN, but is present in the 2.0sp1 version of the
102                 // class
103                 protected override void Unmerge (ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
104                 {
105                         // Why override?
106                         base.Unmerge (sourceElement, parentElement, saveMode);
107                 }
108                 
109                 [ConfigurationProperty ("group")]
110                 public ProfileGroupSettingsCollection GroupSettings {
111                         get { return groupSettings; }
112                 }
113
114                 protected override ConfigurationPropertyCollection Properties {
115                         get { return properties; }
116                 }
117
118                 protected override bool ThrowOnDuplicate {
119                         get { return true; }
120                 }
121
122                 // Why override?
123                 protected override bool IsModified ()
124                 {
125                         return base.IsModified ();
126                 }
127
128                 // Why override?
129                 protected override void ResetModified ()
130                 {
131                         base.ResetModified ();
132                 }
133                 
134                 protected override void Reset (ConfigurationElement parentElement)
135                 {
136                         base.Reset (parentElement);
137
138                         RootProfilePropertySettingsCollection root = (RootProfilePropertySettingsCollection) parentElement;
139                         if (root == null)
140                                 return;
141
142                         GroupSettings.ResetInternal (root.GroupSettings);
143                 }
144         }
145 }
146
147 #endif