2 // System.Runtime.Remoting.Channels.AggregateDictionary.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2002 (C) Copyright, Novell, Inc.
9 using System.Collections;
11 namespace System.Runtime.Remoting
13 internal class AggregateDictionary: IDictionary
15 IDictionary[] dictionaries;
19 public AggregateDictionary (IDictionary[] dics)
24 public bool IsFixedSize
29 public bool IsReadOnly
34 public object this [object key]
38 foreach (IDictionary dic in dictionaries)
39 if (dic.Contains (key)) return dic [key];
45 throw new NotSupportedException ();
49 public ICollection Keys
53 if (_keys != null) return _keys;
55 _keys = new ArrayList ();
56 foreach (IDictionary dic in dictionaries)
57 _keys.AddRange (dic.Keys);
62 public ICollection Values
66 if (_values != null) return _values;
68 _values = new ArrayList ();
69 foreach (IDictionary dic in dictionaries)
70 _values.AddRange (dic.Values);
75 public void Add (object key, object value)
77 throw new NotSupportedException ();
82 throw new NotSupportedException ();
85 public bool Contains (object ob)
87 foreach (IDictionary dic in dictionaries)
88 if (dic.Contains (ob)) return true;
92 public IDictionaryEnumerator GetEnumerator ()
94 return new AggregateEnumerator (dictionaries);
97 IEnumerator IEnumerable.GetEnumerator ()
99 return new AggregateEnumerator (dictionaries);
102 public void Remove (object ob)
104 throw new NotSupportedException ();
107 public void CopyTo (Array array, int index)
109 foreach (object ob in this)
110 array.SetValue (ob, index++);
118 foreach (IDictionary dic in dictionaries)
124 public bool IsSynchronized
126 get { return false; }
129 public object SyncRoot
135 internal class AggregateEnumerator: IDictionaryEnumerator
137 IDictionary[] dictionaries;
139 IDictionaryEnumerator currente;
141 public AggregateEnumerator (IDictionary[] dics)
147 public DictionaryEntry Entry
149 get { return currente.Entry; }
154 get { return currente.Key; }
159 get { return currente.Value; }
162 public object Current
164 get { return currente.Current; }
167 public bool MoveNext ()
169 if (pos >= dictionaries.Length) return false;
171 if (!currente.MoveNext())
174 if (pos >= dictionaries.Length) return false;
175 currente = dictionaries [pos].GetEnumerator ();
185 if (dictionaries.Length > 0)
186 currente = dictionaries [0].GetEnumerator ();