* GetChannelSinkProperties.cs: Implemented GetChannelSinkProperties().
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Channels / AggregateDictionary.cs
1 //
2 // System.Runtime.Remoting.Channels.AggregateDictionary.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2002 (C) Copyright, Novell, Inc.
7 //
8
9 using System.Collections;
10
11 namespace System.Runtime.Remoting
12 {
13         internal class AggregateDictionary: IDictionary
14         {
15                 IDictionary[] dictionaries;
16                 ArrayList _values;
17                 ArrayList _keys;
18                 
19                 public AggregateDictionary (IDictionary[] dics)
20                 {
21                         dictionaries = dics;
22                 }
23                 
24                 public bool IsFixedSize 
25                 { 
26                         get { return true; }
27                 }               
28                 
29                 public bool IsReadOnly 
30                 { 
31                         get { return true; }
32                 } 
33                 
34                 public object this [object key]
35                 { 
36                         get 
37                         {
38                                 foreach (IDictionary dic in dictionaries)
39                                         if (dic.Contains (key)) return dic [key];
40                                 return null;
41                         }
42                         
43                         set
44                         {
45                                 throw new NotSupportedException ();
46                         }
47                 }
48                 
49                 public ICollection Keys 
50                 { 
51                         get
52                         {
53                                 if (_keys != null) return _keys;
54                                 
55                                 _keys = new ArrayList ();
56                                 foreach (IDictionary dic in dictionaries)
57                                         _keys.AddRange (dic.Keys);
58                                 return _keys;
59                         }
60                 } 
61                 
62                 public ICollection Values 
63                 { 
64                         get
65                         {
66                                 if (_values != null) return _values;
67                                 
68                                 _values = new ArrayList ();
69                                 foreach (IDictionary dic in dictionaries)
70                                         _values.AddRange (dic.Values);
71                                 return _values;
72                         }
73                 }
74                 
75                 public void Add (object key, object value)
76                 {
77                         throw new NotSupportedException ();
78                 }
79                 
80                 public void Clear ()
81                 {
82                         throw new NotSupportedException ();
83                 }
84                 
85                 public bool Contains (object ob)
86                 {
87                         foreach (IDictionary dic in dictionaries)
88                                 if (dic.Contains (ob)) return true;
89                         return false;
90                 }
91                 
92                 public IDictionaryEnumerator GetEnumerator ()
93                 {
94                         return new AggregateEnumerator (dictionaries);
95                 }
96                 
97                 IEnumerator IEnumerable.GetEnumerator ()
98                 {
99                         return new AggregateEnumerator (dictionaries);
100                 }
101                 
102                 public void Remove (object ob)
103                 {
104                         throw new NotSupportedException ();
105                 }
106                 
107                 public void CopyTo (Array array, int index)
108                 {
109                         foreach (object ob in this)
110                                 array.SetValue (ob, index++);
111                 }
112                 
113                 public int Count 
114                 { 
115                         get
116                         {
117                                 int c = 0;
118                                 foreach (IDictionary dic in dictionaries)
119                                         c += dic.Count;
120                                 return c;
121                         }
122                 }
123                 
124                 public bool IsSynchronized 
125                 { 
126                         get { return false; }
127                 }
128                 
129                 public object SyncRoot 
130                 { 
131                         get { return this; }
132                 } 
133         }
134         
135         internal class AggregateEnumerator: IDictionaryEnumerator
136         {
137                 IDictionary[] dictionaries;
138                 int pos = 0;
139                 IDictionaryEnumerator currente;
140                 
141                 public AggregateEnumerator (IDictionary[] dics)
142                 {
143                         dictionaries = dics;
144                         Reset ();
145                 }
146                 
147                 public DictionaryEntry Entry 
148                 { 
149                         get { return currente.Entry; }
150                 }
151                 
152                 public object Key 
153                 {
154                         get { return currente.Key; }
155                 }
156                 
157                 public object Value 
158                 { 
159                         get { return currente.Value; }
160                 }
161                 
162                 public object Current 
163                 { 
164                         get { return currente.Current; }
165                 }
166                 
167                 public bool MoveNext ()
168                 {
169                         if (pos >= dictionaries.Length) return false;
170
171                         if (!currente.MoveNext()) 
172                         {
173                                 pos++;
174                                 if (pos >= dictionaries.Length) return false;
175                                 currente = dictionaries [pos].GetEnumerator ();
176                                 return MoveNext ();
177                         }
178                         
179                         return true;
180                 }
181                 
182                 public void Reset ()
183                 {
184                         pos = 0;
185                         if (dictionaries.Length > 0)
186                                 currente = dictionaries [0].GetEnumerator ();
187                 }
188         }
189 }