Merge pull request #2080 from upsilon/fix-point-constructor
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / FormsAuthenticationUserCollection.cs
1 //
2 // System.Web.Configuration.FormsAuthenticationUserCollection
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.Configuration;
33 using System.ComponentModel;
34
35 namespace System.Web.Configuration
36 {
37         [ConfigurationCollection (typeof (FormsAuthenticationUser), AddItemName = "user", CollectionType = ConfigurationElementCollectionType.BasicMap)]
38         public sealed class FormsAuthenticationUserCollection : ConfigurationElementCollection
39         {
40                 static ConfigurationPropertyCollection properties;
41
42                 static FormsAuthenticationUserCollection ()
43                 {
44                         properties = new ConfigurationPropertyCollection();
45                 }
46
47                 public FormsAuthenticationUserCollection ()
48                 {
49                 }
50
51                 public void Add (FormsAuthenticationUser user)
52                 {
53                         BaseAdd (user);
54                 }
55
56                 public void Clear ()
57                 {
58                         BaseClear ();
59                 }
60
61                 protected override ConfigurationElement CreateNewElement ()
62                 {
63                         return new FormsAuthenticationUser("", "");
64                 }
65
66                 public FormsAuthenticationUser Get (int index)
67                 {
68                         return (FormsAuthenticationUser) BaseGet (index);
69                 }
70
71                 public FormsAuthenticationUser Get (string name)
72                 {
73                         return (FormsAuthenticationUser) BaseGet (name);
74                 }
75
76                 protected override object GetElementKey (ConfigurationElement element)
77                 {
78                         return ((FormsAuthenticationUser)element).Name;
79                 }
80
81                 public string GetKey (int index)
82                 {
83                         FormsAuthenticationUser user = Get (index);
84                         return user.Name;
85                 }
86
87                 public void Remove (string name)
88                 {
89                         BaseRemove (name);
90                 }
91
92                 public void RemoveAt (int index)
93                 {
94                         BaseRemoveAt (index);
95                 }
96
97                 public void Set (FormsAuthenticationUser user)
98                 {
99                         FormsAuthenticationUser existing = Get (user.Name);
100
101                         if (existing == null) {
102                                 Add (user);
103                         }
104                         else {
105                                 int index = BaseIndexOf (existing);
106                                 RemoveAt (index);
107                                 BaseAdd (index, user);
108                         }
109                 }
110
111                 public string[ ] AllKeys {
112                         get {
113                                 string[] keys = new string[Count];
114                                 for (int i = 0; i < Count; i ++)
115                                         keys[i] = this[i].Name;
116                                 return keys;
117                         }
118                 }
119
120                 public override ConfigurationElementCollectionType CollectionType {
121                         get { return ConfigurationElementCollectionType.BasicMap; }
122                 }
123
124                 protected override string ElementName {
125                         get { return "user"; }
126                 }
127
128                 protected internal override ConfigurationPropertyCollection Properties {
129                         get { return properties; }
130                 }
131
132                 public FormsAuthenticationUser this[int index] {
133                         get { return (FormsAuthenticationUser) Get (index); }
134                         set { if (BaseGet (index) != null) BaseRemoveAt (index); BaseAdd (index, value); }
135                 }
136
137                 public new FormsAuthenticationUser this[string name] {
138                         get { return (FormsAuthenticationUser) Get (name); }
139                 }
140
141                 protected override bool ThrowOnDuplicate {
142                         get { return false; }
143                 }
144         }
145 }
146