2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / System.Runtime.Remoting.Channels / AggregateDictionary.cs
blob80d06c9c97631057e742eafceda8a84f53485b3a
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 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
34 namespace System.Runtime.Remoting.Channels
36 [System.Runtime.InteropServices.ComVisible (true)]
37 internal class AggregateDictionary: IDictionary
39 IDictionary[] dictionaries;
40 ArrayList _values;
41 ArrayList _keys;
43 public AggregateDictionary (IDictionary[] dics)
45 dictionaries = dics;
48 public bool IsFixedSize
50 get { return true; }
53 public bool IsReadOnly
55 get { return true; }
58 public object this [object key]
60 get
62 foreach (IDictionary dic in dictionaries)
63 if (dic.Contains (key)) return dic [key];
64 return null;
67 set
69 throw new NotSupportedException ();
73 public ICollection Keys
75 get
77 if (_keys != null) return _keys;
79 _keys = new ArrayList ();
80 foreach (IDictionary dic in dictionaries)
81 _keys.AddRange (dic.Keys);
82 return _keys;
86 public ICollection Values
88 get
90 if (_values != null) return _values;
92 _values = new ArrayList ();
93 foreach (IDictionary dic in dictionaries)
94 _values.AddRange (dic.Values);
95 return _values;
99 public void Add (object key, object value)
101 throw new NotSupportedException ();
104 public void Clear ()
106 throw new NotSupportedException ();
109 public bool Contains (object ob)
111 foreach (IDictionary dic in dictionaries)
112 if (dic.Contains (ob)) return true;
113 return false;
116 public IDictionaryEnumerator GetEnumerator ()
118 return new AggregateEnumerator (dictionaries);
121 IEnumerator IEnumerable.GetEnumerator ()
123 return new AggregateEnumerator (dictionaries);
126 public void Remove (object ob)
128 throw new NotSupportedException ();
131 public void CopyTo (Array array, int index)
133 foreach (object ob in this)
134 array.SetValue (ob, index++);
137 public int Count
141 int c = 0;
142 foreach (IDictionary dic in dictionaries)
143 c += dic.Count;
144 return c;
148 public bool IsSynchronized
150 get { return false; }
153 public object SyncRoot
155 get { return this; }
159 internal class AggregateEnumerator: IDictionaryEnumerator
161 IDictionary[] dictionaries;
162 int pos = 0;
163 IDictionaryEnumerator currente;
165 public AggregateEnumerator (IDictionary[] dics)
167 dictionaries = dics;
168 Reset ();
171 public DictionaryEntry Entry
173 get { return currente.Entry; }
176 public object Key
178 get { return currente.Key; }
181 public object Value
183 get { return currente.Value; }
186 public object Current
188 get { return currente.Current; }
191 public bool MoveNext ()
193 if (pos >= dictionaries.Length) return false;
195 if (!currente.MoveNext())
197 pos++;
198 if (pos >= dictionaries.Length) return false;
199 currente = dictionaries [pos].GetEnumerator ();
200 return MoveNext ();
203 return true;
206 public void Reset ()
208 pos = 0;
209 if (dictionaries.Length > 0)
210 currente = dictionaries [0].GetEnumerator ();