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