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 internal class AggregateDictionary: IDictionary
38 IDictionary[] dictionaries;
42 public AggregateDictionary (IDictionary[] dics)
47 public bool IsFixedSize
52 public bool IsReadOnly
57 public object this [object key]
61 foreach (IDictionary dic in dictionaries)
62 if (dic.Contains (key)) return dic [key];
68 throw new NotSupportedException ();
72 public ICollection Keys
76 if (_keys != null) return _keys;
78 _keys = new ArrayList ();
79 foreach (IDictionary dic in dictionaries)
80 _keys.AddRange (dic.Keys);
85 public ICollection Values
89 if (_values != null) return _values;
91 _values = new ArrayList ();
92 foreach (IDictionary dic in dictionaries)
93 _values.AddRange (dic.Values);
98 public void Add (object key, object value)
100 throw new NotSupportedException ();
105 throw new NotSupportedException ();
108 public bool Contains (object ob)
110 foreach (IDictionary dic in dictionaries)
111 if (dic.Contains (ob)) return true;
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++);
141 foreach (IDictionary dic in dictionaries)
147 public bool IsSynchronized
149 get { return false; }
152 public object SyncRoot
158 internal class AggregateEnumerator: IDictionaryEnumerator
160 IDictionary[] dictionaries;
162 IDictionaryEnumerator currente;
164 public AggregateEnumerator (IDictionary[] dics)
170 public DictionaryEntry Entry
172 get { return currente.Entry; }
177 get { return currente.Key; }
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())
197 if (pos >= dictionaries.Length) return false;
198 currente = dictionaries [pos].GetEnumerator ();
208 if (dictionaries.Length > 0)
209 currente = dictionaries [0].GetEnumerator ();