Backport of some changes from svn trunk - performance improvement and a fix for bug...
[mono-project.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / ProfilePropertySettingsCollection.cs
blobbc540d8fd450ffb49e4c894029e47af5bc2d7745
1 //
2 // System.Web.Configuration.ProfilePropertySettingsCollection
3 //
4 // Authors:
5 // Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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.
31 #if NET_2_0
33 using System;
34 using System.Configuration;
35 using System.Xml;
37 namespace System.Web.Configuration
39 [ConfigurationCollection (typeof (ProfilePropertySettings), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
40 public class ProfilePropertySettingsCollection : ConfigurationElementCollection
42 static ConfigurationPropertyCollection properties;
44 static ProfilePropertySettingsCollection ()
46 properties = new ConfigurationPropertyCollection ();
49 public void Add (ProfilePropertySettings propertySettings)
51 BaseAdd (propertySettings);
54 public void Clear ()
56 BaseClear ();
59 protected override ConfigurationElement CreateNewElement ()
61 return new ProfilePropertySettings ();
64 public ProfilePropertySettings Get (int index)
66 return (ProfilePropertySettings) BaseGet (index);
69 public ProfilePropertySettings Get (string name)
71 return (ProfilePropertySettings) BaseGet (name);
74 protected override object GetElementKey (ConfigurationElement element)
76 return ((ProfilePropertySettings)element).Name;
79 protected override bool OnDeserializeUnrecognizedElement (string elementName, XmlReader reader)
81 /* Disabled: pending investigation
83 if (elementName == "clear" || elementName == "group") {
84 throw new ConfigurationErrorsException (String.Format ("{0} is not permitted here", elementName), reader);
88 return base.OnDeserializeUnrecognizedElement (elementName, reader);
91 public string GetKey (int index)
93 ProfilePropertySettings s = Get (index);
94 if (s == null)
95 return null;
97 return s.Name;
100 public int IndexOf (ProfilePropertySettings propertySettings)
102 return BaseIndexOf (propertySettings);
105 public void Remove (string name)
107 BaseRemove (name);
110 public void RemoveAt (int index)
112 BaseRemoveAt (index);
115 public void Set (ProfilePropertySettings propertySettings)
117 ProfilePropertySettings existing = Get (propertySettings.Name);
119 if (existing == null) {
120 Add (propertySettings);
122 else {
123 int index = BaseIndexOf (existing);
124 RemoveAt (index);
125 BaseAdd (index, propertySettings);
129 public string[ ] AllKeys {
130 get {
131 string[] keys = new string[Count];
132 for (int i = 0; i < Count; i ++)
133 keys[i] = this[i].Name;
134 return keys;
138 protected virtual bool AllowClear {
139 get {
140 return false;
144 public ProfilePropertySettings this[int index] {
145 get { return Get (index); }
146 set { if (Get (index) != null) BaseRemoveAt (index); BaseAdd (index, value); }
149 public new ProfilePropertySettings this [string name] {
150 get { return (ProfilePropertySettings) base.BaseGet (name); }
153 protected override bool ThrowOnDuplicate {
154 get {
155 return true;
159 protected override ConfigurationPropertyCollection Properties {
160 get { return properties; }
165 #endif