Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Components / DictionaryAdapter / Castle.Components.DictionaryAdapter / NameValueCollectionAdapter.cs
blobc85b61864b96f94ebaceb76e0536005cfbbb70a1
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.Components.DictionaryAdapter
17 using System;
18 using System.Collections.Specialized;
20 /// <summary>
21 ///
22 /// </summary>
23 public class NameValueCollectionAdapter : AbstractDictionaryAdapter
25 private readonly NameValueCollection nameValues;
27 /// <summary>
28 /// Initializes a new instance of the <see cref="NameValueCollectionAdapter"/> class.
29 /// </summary>
30 /// <param name="nameValues">The name values.</param>
31 public NameValueCollectionAdapter(NameValueCollection nameValues)
33 this.nameValues = nameValues;
36 /// <summary>
37 /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"></see> object is read-only.
38 /// </summary>
39 /// <value></value>
40 /// <returns>true if the <see cref="T:System.Collections.IDictionary"></see> object is read-only; otherwise, false.</returns>
41 public override bool IsReadOnly
43 get { return false; }
46 /// <summary>
47 /// Determines whether the <see cref="T:System.Collections.IDictionary"></see> object contains an element with the specified key.
48 /// </summary>
49 /// <param name="key">The key to locate in the <see cref="T:System.Collections.IDictionary"></see> object.</param>
50 /// <returns>
51 /// true if the <see cref="T:System.Collections.IDictionary"></see> contains an element with the key; otherwise, false.
52 /// </returns>
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;
59 /// <summary>
60 /// Gets or sets the <see cref="System.Object"/> with the specified key.
61 /// </summary>
62 /// <value></value>
63 public override object this[object key]
65 get { return nameValues[key.ToString()]; }
66 set
68 String val = (value != null) ? value.ToString() : null;
69 nameValues[key.ToString()] = val;
73 /// <summary>
74 /// Adapts the specified name values.
75 /// </summary>
76 /// <param name="nameValues">The name values.</param>
77 /// <returns></returns>
78 public static NameValueCollectionAdapter Adapt(NameValueCollection nameValues)
80 return new NameValueCollectionAdapter(nameValues);