More working tests.
[castle.git] / Core / Castle.Core / ReflectionBasedDictionaryAdapter.cs
blob9f04549d4979db7b0d912b186f22219fc1cbe9df
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.Specialized;
20 using System.Reflection;
22 /// <summary>
23 /// Pendent
24 /// </summary>
25 public class ReflectionBasedDictionaryAdapter : IDictionary
27 private readonly IDictionary properties = new HybridDictionary(true);
29 /// <summary>
30 /// Initializes a new instance of the <see cref="ReflectionBasedDictionaryAdapter"/> class.
31 /// </summary>
32 /// <param name="target">The target.</param>
33 public ReflectionBasedDictionaryAdapter(object target)
35 if (target == null)
37 throw new ArgumentNullException("target");
40 Type targetType = target.GetType();
42 foreach(PropertyInfo property in targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
44 object value = property.GetValue(target, null);
46 properties[property.Name] = value;
50 /// <summary>
51 /// Determines whether the <see cref="T:System.Collections.IDictionary"/> object contains an element with the specified key.
52 /// </summary>
53 /// <param name="key">The key to locate in the <see cref="T:System.Collections.IDictionary"/> object.</param>
54 /// <returns>
55 /// true if the <see cref="T:System.Collections.IDictionary"/> contains an element with the key; otherwise, false.
56 /// </returns>
57 /// <exception cref="T:System.ArgumentNullException">
58 /// <paramref name="key"/> is null. </exception>
59 public bool Contains(object key)
61 return properties.Contains(key);
64 /// <summary>
65 /// Gets or sets the <see cref="System.Object"/> with the specified key.
66 /// </summary>
67 /// <value></value>
68 public object this[object key]
70 get
72 return properties[key];
74 set { throw new NotImplementedException(); }
77 /// <summary>
78 /// Adds an element with the provided key and value to the <see cref="T:System.Collections.IDictionary"/> object.
79 /// </summary>
80 /// <param name="key">The <see cref="T:System.Object"/> to use as the key of the element to add.</param>
81 /// <param name="value">The <see cref="T:System.Object"/> to use as the value of the element to add.</param>
82 /// <exception cref="T:System.ArgumentNullException">
83 /// <paramref name="key"/> is null. </exception>
84 /// <exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.IDictionary"/> object. </exception>
85 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.IDictionary"/> is read-only.-or- The <see cref="T:System.Collections.IDictionary"/> has a fixed size. </exception>
86 public void Add(object key, object value)
88 throw new NotImplementedException();
91 /// <summary>
92 /// Removes all elements from the <see cref="T:System.Collections.IDictionary"/> object.
93 /// </summary>
94 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.IDictionary"/> object is read-only. </exception>
95 public void Clear()
97 throw new NotImplementedException();
100 /// <summary>
101 /// Returns an <see cref="T:System.Collections.IDictionaryEnumerator"/> object for the <see cref="T:System.Collections.IDictionary"/> object.
102 /// </summary>
103 /// <returns>
104 /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> object for the <see cref="T:System.Collections.IDictionary"/> object.
105 /// </returns>
106 IDictionaryEnumerator IDictionary.GetEnumerator()
108 return properties.GetEnumerator();
111 /// <summary>
112 /// Removes the element with the specified key from the <see cref="T:System.Collections.IDictionary"/> object.
113 /// </summary>
114 /// <param name="key">The key of the element to remove.</param>
115 /// <exception cref="T:System.ArgumentNullException">
116 /// <paramref name="key"/> is null. </exception>
117 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.IDictionary"/> object is read-only.-or- The <see cref="T:System.Collections.IDictionary"/> has a fixed size. </exception>
118 public void Remove(object key)
122 /// <summary>
123 /// Gets an <see cref="T:System.Collections.ICollection"/> object containing the keys of the <see cref="T:System.Collections.IDictionary"/> object.
124 /// </summary>
125 /// <value></value>
126 /// <returns>An <see cref="T:System.Collections.ICollection"/> object containing the keys of the <see cref="T:System.Collections.IDictionary"/> object.</returns>
127 public ICollection Keys
129 get { return properties.Keys; }
132 /// <summary>
133 /// Gets an <see cref="T:System.Collections.ICollection"/> object containing the values in the <see cref="T:System.Collections.IDictionary"/> object.
134 /// </summary>
135 /// <value></value>
136 /// <returns>An <see cref="T:System.Collections.ICollection"/> object containing the values in the <see cref="T:System.Collections.IDictionary"/> object.</returns>
137 public ICollection Values
139 get { return properties.Values; }
142 /// <summary>
143 /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"/> object is read-only.
144 /// </summary>
145 /// <value></value>
146 /// <returns>true if the <see cref="T:System.Collections.IDictionary"/> object is read-only; otherwise, false.</returns>
147 public bool IsReadOnly
149 get { return true; }
152 /// <summary>
153 /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"/> object has a fixed size.
154 /// </summary>
155 /// <value></value>
156 /// <returns>true if the <see cref="T:System.Collections.IDictionary"/> object has a fixed size; otherwise, false.</returns>
157 public bool IsFixedSize
159 get { throw new NotImplementedException(); }
162 /// <summary>
163 /// Copies the elements of the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
164 /// </summary>
165 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param>
166 /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
167 /// <exception cref="T:System.ArgumentNullException">
168 /// <paramref name="array"/> is null. </exception>
169 /// <exception cref="T:System.ArgumentOutOfRangeException">
170 /// <paramref name="index"/> is less than zero. </exception>
171 /// <exception cref="T:System.ArgumentException">
172 /// <paramref name="array"/> is multidimensional.-or- <paramref name="index"/> is equal to or greater than the length of <paramref name="array"/>.-or- The number of elements in the source <see cref="T:System.Collections.ICollection"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>. </exception>
173 /// <exception cref="T:System.ArgumentException">The type of the source <see cref="T:System.Collections.ICollection"/> cannot be cast automatically to the type of the destination <paramref name="array"/>. </exception>
174 public void CopyTo(Array array, int index)
176 throw new NotImplementedException();
179 /// <summary>
180 /// Gets the number of elements contained in the <see cref="T:System.Collections.ICollection"/>.
181 /// </summary>
182 /// <value></value>
183 /// <returns>The number of elements contained in the <see cref="T:System.Collections.ICollection"/>.</returns>
184 public int Count
186 get { return properties.Count; }
189 /// <summary>
190 /// Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
191 /// </summary>
192 /// <value></value>
193 /// <returns>An object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.</returns>
194 public object SyncRoot
196 get { return properties; }
199 /// <summary>
200 /// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized (thread safe).
201 /// </summary>
202 /// <value></value>
203 /// <returns>true if access to the <see cref="T:System.Collections.ICollection"/> is synchronized (thread safe); otherwise, false.</returns>
204 public bool IsSynchronized
206 get { return false; }
209 /// <summary>
210 /// Returns an enumerator that iterates through a collection.
211 /// </summary>
212 /// <returns>
213 /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
214 /// </returns>
215 public IEnumerator GetEnumerator()
217 return properties.GetEnumerator();