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
37 [System.Runtime.InteropServices.ComVisible (true)]
39 internal class AggregateDictionary: IDictionary
41 IDictionary[] dictionaries;
45 public AggregateDictionary (IDictionary[] dics)
50 public bool IsFixedSize
55 public bool IsReadOnly
60 public object this [object key]
64 foreach (IDictionary dic in dictionaries)
65 if (dic.Contains (key)) return dic [key];
71 throw new NotSupportedException ();
75 public ICollection Keys
79 if (_keys != null) return _keys;
81 _keys = new ArrayList ();
82 foreach (IDictionary dic in dictionaries)
83 _keys.AddRange (dic.Keys);
88 public ICollection Values
92 if (_values != null) return _values;
94 _values = new ArrayList ();
95 foreach (IDictionary dic in dictionaries)
96 _values.AddRange (dic.Values);
101 public void Add (object key, object value)
103 throw new NotSupportedException ();
108 throw new NotSupportedException ();
111 public bool Contains (object ob)
113 foreach (IDictionary dic in dictionaries)
114 if (dic.Contains (ob)) return true;
118 public IDictionaryEnumerator GetEnumerator ()
120 return new AggregateEnumerator (dictionaries);
123 IEnumerator IEnumerable.GetEnumerator ()
125 return new AggregateEnumerator (dictionaries);
128 public void Remove (object ob)
130 throw new NotSupportedException ();
133 public void CopyTo (Array array, int index)
135 foreach (object ob in this)
136 array.SetValue (ob, index++);
144 foreach (IDictionary dic in dictionaries)
150 public bool IsSynchronized
152 get { return false; }
155 public object SyncRoot
161 internal class AggregateEnumerator: IDictionaryEnumerator
163 IDictionary[] dictionaries;
165 IDictionaryEnumerator currente;
167 public AggregateEnumerator (IDictionary[] dics)
173 public DictionaryEntry Entry
175 get { return currente.Entry; }
180 get { return currente.Key; }
185 get { return currente.Value; }
188 public object Current
190 get { return currente.Current; }
193 public bool MoveNext ()
195 if (pos >= dictionaries.Length) return false;
197 if (!currente.MoveNext())
200 if (pos >= dictionaries.Length) return false;
201 currente = dictionaries [pos].GetEnumerator ();
211 if (dictionaries.Length > 0)
212 currente = dictionaries [0].GetEnumerator ();