Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Core / Castle.Core / StringObjectDictionaryAdapter.cs
bloba5fed9a45511e0d64c627125cc02a76a4377945f
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core
17 using System;
18 using System.Collections;
19 using System.Collections.Generic;
21 public class StringObjectDictionaryAdapter : IDictionary<string,object>
23 private readonly IDictionary dictionary;
25 public StringObjectDictionaryAdapter(IDictionary dictionary)
27 this.dictionary = dictionary;
30 bool IDictionary<string, object>.ContainsKey(string key)
32 return dictionary.Contains(key);
35 void IDictionary<string, object>.Add(string key, object value)
37 throw new NotImplementedException();
40 bool IDictionary<string, object>.Remove(string key)
42 throw new NotImplementedException();
45 bool IDictionary<string, object>.TryGetValue(string key, out object value)
47 value = null;
48 if (dictionary.Contains(key))
50 value = dictionary[key];
51 return true;
53 else
55 return false;
59 object IDictionary<string, object>.this[string key]
61 get { return dictionary[key]; }
62 set { throw new NotImplementedException(); }
65 ICollection<string> IDictionary<string, object>.Keys
67 get
69 string[] keys = new string[Count];
70 dictionary.Keys.CopyTo(keys, 0);
71 return keys;
75 ICollection<object> IDictionary<string, object>.Values
77 get
79 object[] values = new object[Count];
80 dictionary.Values.CopyTo(values, 0);
81 return values;
85 void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
87 throw new NotImplementedException();
90 bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> item)
92 throw new NotImplementedException();
95 void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
97 throw new NotImplementedException();
100 bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
102 throw new NotImplementedException();
105 IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator()
107 return new EnumeratorAdapter(this);
110 public bool Contains(object key)
112 return dictionary.Contains(key);
115 public void Add(object key, object value)
117 dictionary.Add(key, value);
120 public void Clear()
122 dictionary.Clear();
125 public void Remove(object key)
127 dictionary.Remove(key);
130 public object this[object key]
132 get { return dictionary[key]; }
133 set { dictionary[key] = value; }
136 public ICollection Keys
138 get { return dictionary.Keys; }
141 public ICollection Values
143 get { return dictionary.Values; }
146 public bool IsReadOnly
148 get { return dictionary.IsReadOnly; }
151 public bool IsFixedSize
153 get { return dictionary.IsFixedSize; }
156 public void CopyTo(Array array, int index)
158 dictionary.CopyTo(array, index);
161 public int Count
163 get { return dictionary.Count; }
166 public object SyncRoot
168 get { return dictionary.SyncRoot; }
171 public bool IsSynchronized
173 get { return dictionary.IsSynchronized; }
176 public IEnumerator GetEnumerator()
178 return ((IEnumerable) dictionary).GetEnumerator();
181 internal class EnumeratorAdapter : IEnumerator<KeyValuePair<string, object>>
183 private readonly StringObjectDictionaryAdapter adapter;
184 private IEnumerator<string> keyEnumerator;
185 private string currentKey;
186 private object currentValue;
188 public EnumeratorAdapter(StringObjectDictionaryAdapter adapter)
190 this.adapter = adapter;
191 keyEnumerator = ((IDictionary<string, object>) adapter).Keys.GetEnumerator();
194 public bool MoveNext()
196 if (keyEnumerator.MoveNext())
198 currentKey = keyEnumerator.Current;
199 currentValue = adapter[currentKey];
200 return true;
203 return false;
206 public void Reset()
208 keyEnumerator.Reset();
211 public object Current
213 get { return new KeyValuePair<string, object>(currentKey, currentValue); }
216 KeyValuePair<string, object> IEnumerator<KeyValuePair<string, object>>.Current
218 get { return new KeyValuePair<string, object>(currentKey, currentValue); }
221 public void Dispose()