2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / AggregateDictionary.cs
blob18559d05b1f8cf3862af6ebb0d229c03437acc40
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 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
32 namespace System.Runtime.Remoting.Channels.Http
34 internal class AggregateDictionary : IDictionary
36 IDictionary[] dictionaries;
37 ArrayList _values;
38 ArrayList _keys;
40 public AggregateDictionary (IDictionary[] dics)
42 dictionaries = dics;
45 public bool IsFixedSize
47 get { return true; }
50 public bool IsReadOnly
52 get { return true; }
55 public object this[object key]
57 get
59 foreach (IDictionary dic in dictionaries)
60 if (dic.Contains (key)) return dic[key];
61 return null;
64 set
66 foreach (IDictionary dic in dictionaries)
67 if (dic.Contains (key))
68 dic[key] = value;
72 public ICollection Keys
74 get
76 if (_keys != null) return _keys;
78 _keys = new ArrayList ();
79 foreach (IDictionary dic in dictionaries)
80 _keys.AddRange (dic.Keys);
81 return _keys;
85 public ICollection Values
87 get
89 if (_values != null) return _values;
91 _values = new ArrayList ();
92 foreach (IDictionary dic in dictionaries)
93 _values.AddRange (dic.Values);
94 return _values;
98 public void Add (object key, object value)
100 throw new NotSupportedException ();
103 public void Clear ()
105 throw new NotSupportedException ();
108 public bool Contains (object ob)
110 foreach (IDictionary dic in dictionaries)
111 if (dic.Contains (ob)) return true;
112 return false;
115 public IDictionaryEnumerator GetEnumerator ()
117 return new AggregateEnumerator (dictionaries);
120 IEnumerator IEnumerable.GetEnumerator ()
122 return new AggregateEnumerator (dictionaries);
125 public void Remove (object ob)
127 throw new NotSupportedException ();
130 public void CopyTo (Array array, int index)
132 foreach (object ob in this)
133 array.SetValue (ob, index++);
136 public int Count
140 int c = 0;
141 foreach (IDictionary dic in dictionaries)
142 c += dic.Count;
143 return c;
147 public bool IsSynchronized
149 get { return false; }
152 public object SyncRoot
154 get { return this; }
158 internal class AggregateEnumerator : IDictionaryEnumerator
160 IDictionary[] dictionaries;
161 int pos = 0;
162 IDictionaryEnumerator currente;
164 public AggregateEnumerator (IDictionary[] dics)
166 dictionaries = dics;
167 Reset ();
170 public DictionaryEntry Entry
172 get { return currente.Entry; }
175 public object Key
177 get { return currente.Key; }
180 public object Value
182 get { return currente.Value; }
185 public object Current
187 get { return currente.Current; }
190 public bool MoveNext ()
192 if (pos >= dictionaries.Length) return false;
194 if (!currente.MoveNext ()) {
195 pos++;
196 if (pos >= dictionaries.Length) return false;
197 currente = dictionaries[pos].GetEnumerator ();
198 return MoveNext ();
201 return true;
204 public void Reset ()
206 pos = 0;
207 if (dictionaries.Length > 0)
208 currente = dictionaries[0].GetEnumerator ();