1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
.MonoRail
.Framework
.Internal
18 using System
.Collections
;
19 using System
.Collections
.Specialized
;
22 /// Simple strong typed dictionary for IResource instances.
24 public class ResourceDictionary
: ICollection
26 private HybridDictionary map
= new HybridDictionary(true);
29 /// Adds the specified key.
31 /// <param name="key">The key.</param>
32 /// <param name="resource">The resource.</param>
33 public void Add(object key
, IResource resource
)
35 map
.Add(key
, resource
);
39 /// Gets or sets the <see cref="Castle.MonoRail.Framework.IResource"/> with the specified key.
42 public IResource
this[object key
]
44 get { return map[key] as IResource; }
45 set { map[key] = value; }
49 /// Gets the number of elements contained in the <see cref="T:System.Collections.ICollection"></see>.
52 /// <returns>The number of elements contained in the <see cref="T:System.Collections.ICollection"></see>.</returns>
55 get { return map.Count; }
59 /// Removes the specified key.
61 /// <param name="key">The key.</param>
62 public void Remove(object key
)
68 /// Determines whether the resource contains the specified key.
70 /// <param name="key">The key.</param>
72 /// <c>true</c> if the resource contains it; otherwise, <c>false</c>.
74 public bool Contains(object key
)
76 return map
.Contains(key
);
80 /// Clears this instance.
90 /// <value>The values.</value>
91 public ICollection Values
93 get { return map.Values; }
99 /// <value>The keys.</value>
100 public ICollection Keys
102 get { return map.Keys; }
105 #region ICollection Members
108 /// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe).
111 /// <returns>true if access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe); otherwise, false.</returns>
112 public bool IsSynchronized
114 get { return map.IsSynchronized; }
118 /// Copies the elements of the <see cref="T:System.Collections.ICollection"></see> to an <see cref="T:System.Array"></see>, starting at a particular <see cref="T:System.Array"></see> index.
120 /// <param name="array">The one-dimensional <see cref="T:System.Array"></see> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"></see>. The <see cref="T:System.Array"></see> must have zero-based indexing.</param>
121 /// <param name="index">The zero-based index in array at which copying begins.</param>
122 /// <exception cref="T:System.ArgumentNullException">array is null. </exception>
123 /// <exception cref="T:System.ArgumentOutOfRangeException">index is less than zero. </exception>
124 /// <exception cref="T:System.ArgumentException">array is multidimensional.-or- index is equal to or greater than the length of array.-or- The number of elements in the source <see cref="T:System.Collections.ICollection"></see> is greater than the available space from index to the end of the destination array. </exception>
125 /// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.ICollection"></see> cannot be cast automatically to the type of the destination array. </exception>
126 public void CopyTo(Array array
, int index
)
128 map
.CopyTo(array
, index
);
132 /// Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.
135 /// <returns>An object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.</returns>
136 public object SyncRoot
138 get { return map.SyncRoot; }
143 #region IEnumerable Members
146 /// Returns an enumerator that iterates through a collection.
149 /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
151 IEnumerator System
.Collections
.IEnumerable
.GetEnumerator()
153 return map
.GetEnumerator();