2 // System.Web.UI.ExpressionBindingCollection.cs
5 // Sanjay Gupta gsanjay@novell.com)
7 // (C) 2004-2010 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.
32 using System.ComponentModel;
33 using System.Collections;
35 namespace System.Web.UI {
37 public sealed class ExpressionBindingCollection : ICollection, IEnumerable
39 static readonly object changedEvent = new object ();
44 EventHandlerList events = new EventHandlerList ();
46 public event EventHandler Changed {
47 add { events.AddHandler (changedEvent, value); }
48 remove { events.RemoveHandler (changedEvent, value); }
51 public ExpressionBindingCollection ()
53 list = new Hashtable ();
54 removed = new ArrayList ();
58 get { return list.Count; }
61 public bool IsReadOnly {
62 get { return list.IsReadOnly; }
65 public bool IsSynchronized {
66 get { return list.IsSynchronized; }
69 public ExpressionBinding this [string propertyName] {
70 get { return list [propertyName] as ExpressionBinding; }
73 public ICollection RemovedBindings {
74 get { return removed; }
77 public object SyncRoot {
78 get { return list.SyncRoot; }
81 public void Add (ExpressionBinding binding)
83 list.Add (binding.PropertyName, binding);
84 OnChanged (new EventArgs ());
91 OnChanged (new EventArgs ());
94 public bool Contains (string propName)
96 return list.Contains (propName);
99 public void CopyTo (Array array, int index)
101 list.CopyTo (array, index);
104 public void CopyTo (ExpressionBinding [] array, int index)
107 throw new ArgumentNullException ("Index cannot be negative");
108 if (index >= array.Length)
109 throw new ArgumentException ("Index cannot be greater than or equal to length of array passed");
110 if (list.Count > (array.Length - index + 1))
111 throw new ArgumentException ("Number of elements in source is greater than available space from index to end of destination");
113 foreach (string key in list.Keys)
114 array [index++] = (ExpressionBinding) list [key];
117 public IEnumerator GetEnumerator ()
119 return list.GetEnumerator ();
122 public void Remove (ExpressionBinding binding)
124 Remove(binding.PropertyName, true);
127 public void Remove (string propertyName)
129 Remove (propertyName, true);
132 public void Remove (string propertyName, bool addToRemovedList)
134 if (addToRemovedList)
135 removed.Add (String.Empty);
137 removed.Add (propertyName);
139 list.Remove (propertyName);
140 OnChanged (new EventArgs ());
143 void OnChanged (EventArgs e)
145 EventHandler eh = events [changedEvent] as EventHandler;