2 // System.Web.UI.ExpressionBindingCollection.cs
5 // Sanjay Gupta gsanjay@novell.com)
7 // (C) 2004 Novell, Inc. (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.ComponentModel;
34 using System.Collections;
36 namespace System.Web.UI {
38 public sealed class ExpressionBindingCollection : ICollection, IEnumerable
40 static readonly object changedEvent = new object ();
45 EventHandlerList events = new EventHandlerList ();
47 public event EventHandler Changed {
48 add { events.AddHandler (changedEvent, value); }
49 remove { events.RemoveHandler (changedEvent, value); }
52 public ExpressionBindingCollection ()
54 list = new Hashtable ();
55 removed = new ArrayList ();
59 get { return list.Count; }
62 public bool IsReadOnly {
63 get { return list.IsReadOnly; }
66 public bool IsSynchronized {
67 get { return list.IsSynchronized; }
70 public ExpressionBinding this [string propertyName] {
71 get { return list [propertyName] as ExpressionBinding; }
74 public ICollection RemovedBindings {
75 get { return removed; }
78 public object SyncRoot {
79 get { return list.SyncRoot; }
82 public void Add (ExpressionBinding binding)
84 list.Add (binding.PropertyName, binding);
85 OnChanged (new EventArgs ());
92 OnChanged (new EventArgs ());
95 public bool Contains (string propertyName)
97 return list.Contains (propertyName);
100 public void CopyTo (Array array, int index)
102 list.CopyTo (array, index);
105 public void CopyTo (ExpressionBinding [] bindings, int index)
108 throw new ArgumentNullException ("Index cannot be negative");
109 if (index >= bindings.Length)
110 throw new ArgumentException ("Index cannot be greater than or equal to length of array passed");
111 if (list.Count > (bindings.Length - index + 1))
112 throw new ArgumentException ("Number of elements in source is greater than available space from index to end of destination");
114 foreach (string key in list.Keys)
115 bindings [index++] = (ExpressionBinding) list [key];
118 public IEnumerator GetEnumerator ()
120 return list.GetEnumerator ();
123 public void Remove (ExpressionBinding binding)
125 Remove(binding.PropertyName, true);
128 public void Remove (string propertyName)
130 Remove (propertyName, true);
133 public void Remove (string propertyName, bool addToRemovedList)
135 if (addToRemovedList)
136 removed.Add (String.Empty);
138 removed.Add (propertyName);
140 list.Remove (propertyName);
141 OnChanged (new EventArgs ());
144 void OnChanged (EventArgs e)
146 EventHandler eh = events [changedEvent] as EventHandler;