2 // System.Runtime.Remoting.Channels.AggregateDictionary.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2002 (C) Copyright, Novell, Inc.
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
32 namespace System.Runtime.Remoting.Channels.Http
34 internal class AggregateDictionary: IDictionary
36 IDictionary[] dictionaries;
40 public AggregateDictionary (IDictionary[] dics)
45 public bool IsFixedSize
50 public bool IsReadOnly
55 public object this [object key]
59 foreach (IDictionary dic in dictionaries)
60 if (dic.Contains (key)) return dic [key];
66 throw new NotSupportedException ();
70 public ICollection Keys
74 if (_keys != null) return _keys;
76 _keys = new ArrayList ();
77 foreach (IDictionary dic in dictionaries)
78 _keys.AddRange (dic.Keys);
83 public ICollection Values
87 if (_values != null) return _values;
89 _values = new ArrayList ();
90 foreach (IDictionary dic in dictionaries)
91 _values.AddRange (dic.Values);
96 public void Add (object key, object value)
98 throw new NotSupportedException ();
103 throw new NotSupportedException ();
106 public bool Contains (object ob)
108 foreach (IDictionary dic in dictionaries)
109 if (dic.Contains (ob)) return true;
113 public IDictionaryEnumerator GetEnumerator ()
115 return new AggregateEnumerator (dictionaries);
118 IEnumerator IEnumerable.GetEnumerator ()
120 return new AggregateEnumerator (dictionaries);
123 public void Remove (object ob)
125 throw new NotSupportedException ();
128 public void CopyTo (Array array, int index)
130 foreach (object ob in this)
131 array.SetValue (ob, index++);
139 foreach (IDictionary dic in dictionaries)
145 public bool IsSynchronized
147 get { return false; }
150 public object SyncRoot
156 internal class AggregateEnumerator: IDictionaryEnumerator
158 IDictionary[] dictionaries;
160 IDictionaryEnumerator currente;
162 public AggregateEnumerator (IDictionary[] dics)
168 public DictionaryEntry Entry
170 get { return currente.Entry; }
175 get { return currente.Key; }
180 get { return currente.Value; }
183 public object Current
185 get { return currente.Current; }
188 public bool MoveNext ()
190 if (pos >= dictionaries.Length) return false;
192 if (!currente.MoveNext())
195 if (pos >= dictionaries.Length) return false;
196 currente = dictionaries [pos].GetEnumerator ();
206 if (dictionaries.Length > 0)
207 currente = dictionaries [0].GetEnumerator ();