1 // Copyright 2004-2008 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
.Components
.DictionaryAdapter
18 using System
.Collections
.Specialized
;
23 public class NameValueCollectionAdapter
: AbstractDictionaryAdapter
25 private readonly NameValueCollection nameValues
;
28 /// Initializes a new instance of the <see cref="NameValueCollectionAdapter"/> class.
30 /// <param name="nameValues">The name values.</param>
31 public NameValueCollectionAdapter(NameValueCollection nameValues
)
33 this.nameValues
= nameValues
;
37 /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"></see> object is read-only.
40 /// <returns>true if the <see cref="T:System.Collections.IDictionary"></see> object is read-only; otherwise, false.</returns>
41 public override bool IsReadOnly
47 /// Determines whether the <see cref="T:System.Collections.IDictionary"></see> object contains an element with the specified key.
49 /// <param name="key">The key to locate in the <see cref="T:System.Collections.IDictionary"></see> object.</param>
51 /// true if the <see cref="T:System.Collections.IDictionary"></see> contains an element with the key; otherwise, false.
53 /// <exception cref="T:System.ArgumentNullException">key is null. </exception>
54 public override bool Contains(object key
)
56 return Array
.IndexOf(nameValues
.AllKeys
, key
) >= 0;
60 /// Gets or sets the <see cref="System.Object"/> with the specified key.
63 public override object this[object key
]
65 get { return nameValues[key.ToString()]; }
68 String val
= (value != null) ? value.ToString() : null;
69 nameValues
[key
.ToString()] = val
;
74 /// Adapts the specified name values.
76 /// <param name="nameValues">The name values.</param>
77 /// <returns></returns>
78 public static NameValueCollectionAdapter
Adapt(NameValueCollection nameValues
)
80 return new NameValueCollectionAdapter(nameValues
);