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