2002-05-17 Duncan Mak <duncan@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI / DataBindingCollection.cs
1 //
2 // System.Web.UI.DataBindingCollection.cs
3 //
4 // Duncan Mak  (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 using System;
10 using System.Collections;
11
12 namespace System.Web.UI {
13
14         public sealed class DataBindingCollection : ICollection, IEnumerable
15         {
16                 Hashtable list;
17                 ArrayList removed;
18                 
19                 public DataBindingCollection ()
20                 {
21                         list = new Hashtable ();
22                         removed = new ArrayList ();
23                 }
24
25                 public int Count {
26                         get { return list.Count; }
27                 }
28
29                 public bool IsReadOnly {
30                         get { return list.IsReadOnly; }
31                 }
32
33                 public bool IsSynchronized {
34                         get { return list.IsSynchronized; }
35                 }
36
37                 public DataBinding this [string propertyName] {
38                         get { return list [propertyName] as DataBinding; }
39                 }
40
41                 public string [] RemovedBindings {
42                         get { return (string []) removed.ToArray (typeof (string)); }
43                 }
44
45                 public object SyncRoot {
46                         get { return list.SyncRoot; }
47                 }
48
49                 public void Add (DataBinding binding)
50                 {
51                         list.Add (binding.PropertyName, binding);
52                 }
53
54                 public void Clear ()
55                 {
56                         list.Clear ();
57                 }
58
59                 public void CopyTo (Array array, int index)
60                 {
61                         list.CopyTo (array, index);
62                 }
63
64                 public IEnumerator GetEnumerator ()
65                 {
66                         return list.GetEnumerator ();
67                 }
68
69                 public void Remove (DataBinding binding)
70                 {
71                         string key = binding.PropertyName;
72                         Remove (key);
73                 }
74
75                 public void Remove (string propertyName)
76                 {
77                         removed.Add (propertyName);
78                         list.Remove (propertyName);
79                 }
80
81                 public void Remove (string propertyName,
82                                     bool addToRemovedList)
83                 {
84                         if (addToRemovedList)
85                                 removed.Add (String.Empty); // LAMESPEC
86                         else
87                                 removed.Add (propertyName);
88
89                         list.Remove (propertyName);
90                 }
91         }
92 }