In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / System.Web / System.Web.UI / ExpressionBindingCollection.cs
1 //
2 // System.Web.UI.ExpressionBindingCollection.cs
3 //
4 // Authors:
5 //      Sanjay Gupta gsanjay@novell.com)
6 //
7 // (C) 2004 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 using System;
33 using System.Collections;
34
35 namespace System.Web.UI {
36         
37         public sealed class ExpressionBindingCollection : ICollection, IEnumerable
38         {
39                 Hashtable list;
40                 ArrayList removed;
41                 
42                 public ExpressionBindingCollection ()
43                 {
44                         list = new Hashtable ();
45                         removed = new ArrayList ();
46                 }
47
48                 public int Count {
49                         get { return list.Count; }
50                 }
51
52                 public bool IsReadOnly {
53                         get { return list.IsReadOnly; }
54                 }
55
56                 public bool IsSynchronized {
57                         get { return list.IsSynchronized; }
58                 }
59
60                 public ExpressionBinding this [string propertyName] {
61                         get { return list [propertyName] as ExpressionBinding; }
62                 }
63
64                 public ICollection RemovedBindings {
65                         get { return removed; }
66                 }
67
68                 public object SyncRoot {
69                         get { return list.SyncRoot; }
70                 }
71
72                 public void Add (ExpressionBinding binding)
73                 {
74                         list.Add (binding.PropertyName, binding);
75                         OnChanged (new EventArgs ());
76                 }
77
78                 public void Clear ()
79                 {
80                         list.Clear ();
81                         removed.Clear ();
82                         OnChanged (new EventArgs ());
83                 }
84
85                 public bool Contains (string propertyName)
86                 {
87                         return list.Contains (propertyName);
88                 }
89
90                 public void CopyTo (Array array, int index)
91                 {
92                         list.CopyTo (array, index);
93                 }
94
95                 public void CopyTo (ExpressionBinding [] bindings, int index)
96                 {
97                         if (index < 0)
98                                 throw new ArgumentNullException ("Index cannot be negative");
99                         if (index >= bindings.Length)
100                                 throw new ArgumentException ("Index cannot be greater than or equal to length of array passed");            
101                         if (list.Count > (bindings.Length - index + 1))
102                                 throw new ArgumentException ("Number of elements in source is greater than available space from index to end of destination");
103             
104                         foreach (string key in list.Keys)
105                                 bindings [index++] = (ExpressionBinding) list [key];
106                 }
107
108                 public IEnumerator GetEnumerator ()
109                 {
110                         return list.GetEnumerator ();
111                 }
112
113                 public void Remove (ExpressionBinding binding)
114                 {
115                         Remove(binding.PropertyName, true);
116                 }
117
118                 public void Remove (string propertyName)
119                 {
120                         Remove (propertyName, true);            
121                 }
122
123                 public void Remove (string propertyName, bool addToRemovedList)
124                 {
125                         if (addToRemovedList)
126                                 removed.Add (String.Empty); 
127                         else
128                                 removed.Add (propertyName);
129
130                         list.Remove (propertyName);
131                         OnChanged (new EventArgs ());
132                 }
133
134                 public event EventHandler Changed;
135
136                 void OnChanged (EventArgs e)   
137                 {
138                         if (Changed != null)
139                                 Changed (this, e);
140                 }        
141
142         }
143 }
144 #endif