2 // System.Runtime.Remoting.Channels.AggregateDictionary.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2002 (C) Copyright, Novell, Inc.
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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;
43 public AggregateDictionary (IDictionary[] dics)
48 public bool IsFixedSize
53 public bool IsReadOnly
58 public object this [object key]
62 foreach (IDictionary dic in dictionaries)
63 if (dic.Contains (key)) return dic [key];
69 throw new NotSupportedException ();
73 public ICollection Keys
77 if (_keys != null) return _keys;
79 _keys = new ArrayList ();
80 foreach (IDictionary dic in dictionaries)
81 _keys.AddRange (dic.Keys);
86 public ICollection Values
90 if (_values != null) return _values;
92 _values = new ArrayList ();
93 foreach (IDictionary dic in dictionaries)
94 _values.AddRange (dic.Values);
99 public void Add (object key, object value)
101 throw new NotSupportedException ();
106 throw new NotSupportedException ();
109 public bool Contains (object ob)
111 foreach (IDictionary dic in dictionaries)
112 if (dic.Contains (ob)) return true;
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++);
142 foreach (IDictionary dic in dictionaries)
148 public bool IsSynchronized
150 get { return false; }
153 public object SyncRoot
159 internal class AggregateEnumerator: IDictionaryEnumerator
161 IDictionary[] dictionaries;
163 IDictionaryEnumerator currente;
165 public AggregateEnumerator (IDictionary[] dics)
171 public DictionaryEntry Entry
173 get { return currente.Entry; }
178 get { return currente.Key; }
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())
198 if (pos >= dictionaries.Length) return false;
199 currente = dictionaries [pos].GetEnumerator ();
209 if (dictionaries.Length > 0)
210 currente = dictionaries [0].GetEnumerator ();