1
#region Copyright & License
3
// Copyright 2001-2005 The Apache Software Foundation
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
9
// http://www.apache.org/licenses/LICENSE-2.0
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
20
using System.Collections;
22
using System.Runtime.Serialization;
26
namespace log4net.Util
29
/// String keyed object map.
33
/// While this collection is serializable only member
34
/// objects that are serializable will
35
/// be serialized along with this collection.
38
/// <author>Nicko Cadell</author>
39
/// <author>Gert Driesen</author>
41
public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, IDictionary
43
[Serializable] public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, ISerializable, IDictionary
46
#region Public Instance Constructors
53
/// Initializes a new instance of the <see cref="PropertiesDictionary" /> class.
56
public PropertiesDictionary()
63
/// <param name="propertiesDictionary">properties to copy</param>
66
/// Initializes a new instance of the <see cref="PropertiesDictionary" /> class.
69
public PropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) : base(propertiesDictionary)
73
#endregion Public Instance Constructors
75
#region Private Instance Constructors
79
/// Initializes a new instance of the <see cref="PropertiesDictionary" /> class
80
/// with serialized data.
82
/// <param name="info">The <see cref="SerializationInfo" /> that holds the serialized object data.</param>
83
/// <param name="context">The <see cref="StreamingContext" /> that contains contextual information about the source or destination.</param>
86
/// Because this class is sealed the serialization constructor is private.
89
private PropertiesDictionary(SerializationInfo info, StreamingContext context) : base(info, context)
94
#endregion Protected Instance Constructors
96
#region Public Instance Properties
99
/// Gets or sets the value of the property with the specified key.
102
/// The value of the property with the specified key.
104
/// <param name="key">The key of the property to get or set.</param>
107
/// The property value will only be serialized if it is serializable.
108
/// If it cannot be serialized it will be silently ignored if
109
/// a serialization operation is performed.
112
override public object this[string key]
114
get { return InnerHashtable[key]; }
115
set { InnerHashtable[key] = value; }
118
#endregion Public Instance Properties
120
#region Public Instance Methods
123
/// Remove the entry with the specified key from this dictionary
125
/// <param name="key">the key for the entry to remove</param>
128
/// Remove the entry with the specified key from this dictionary
131
public void Remove(string key)
133
InnerHashtable.Remove(key);
136
#endregion Public Instance Methods
138
#region Implementation of IDictionary
141
/// See <see cref="IDictionary.GetEnumerator"/>
143
/// <returns>an enumerator</returns>
146
/// Returns a <see cref="IDictionaryEnumerator"/> over the contest of this collection.
149
IDictionaryEnumerator IDictionary.GetEnumerator()
151
return InnerHashtable.GetEnumerator();
155
/// See <see cref="IDictionary.Remove"/>
157
/// <param name="key">the key to remove</param>
160
/// Remove the entry with the specified key from this dictionary
163
void IDictionary.Remove(object key)
165
InnerHashtable.Remove(key);
169
/// See <see cref="IDictionary.Contains"/>
171
/// <param name="key">the key to lookup in the collection</param>
172
/// <returns><c>true</c> if the collection contains the specified key</returns>
175
/// Test if this collection contains a specified key.
178
bool IDictionary.Contains(object key)
180
return InnerHashtable.Contains(key);
184
/// Remove all properties from the properties collection
188
/// Remove all properties from the properties collection
191
public override void Clear()
193
InnerHashtable.Clear();
197
/// See <see cref="IDictionary.Add"/>
199
/// <param name="key">the key</param>
200
/// <param name="value">the value to store for the key</param>
203
/// Store a value for the specified <see cref="String"/> <paramref name="key"/>.
206
/// <exception cref="ArgumentException">Thrown if the <paramref name="key"/> is not a string</exception>
207
void IDictionary.Add(object key, object value)
209
if (!(key is string))
211
throw new ArgumentException("key must be a string", "key");
213
InnerHashtable.Add(key, value);
217
/// See <see cref="IDictionary.IsReadOnly"/>
224
/// This collection is modifiable. This property always
225
/// returns <c>false</c>.
228
bool IDictionary.IsReadOnly
230
get { return false; }
234
/// See <see cref="IDictionary.this"/>
237
/// The value for the key specified.
241
/// Get or set a value for the specified <see cref="String"/> <paramref name="key"/>.
244
/// <exception cref="ArgumentException">Thrown if the <paramref name="key"/> is not a string</exception>
245
object IDictionary.this[object key]
249
if (!(key is string))
251
throw new ArgumentException("key must be a string", "key");
253
return InnerHashtable[key];
257
if (!(key is string))
259
throw new ArgumentException("key must be a string", "key");
261
InnerHashtable[key] = value;
266
/// See <see cref="IDictionary.Values"/>
268
ICollection IDictionary.Values
270
get { return InnerHashtable.Values; }
274
/// See <see cref="IDictionary.Keys"/>
276
ICollection IDictionary.Keys
278
get { return InnerHashtable.Keys; }
282
/// See <see cref="IDictionary.IsFixedSize"/>
284
bool IDictionary.IsFixedSize
286
get { return false; }
291
#region Implementation of ICollection
294
/// See <see cref="ICollection.CopyTo"/>
296
/// <param name="array"></param>
297
/// <param name="index"></param>
298
void ICollection.CopyTo(Array array, int index)
300
InnerHashtable.CopyTo(array, index);
304
/// See <see cref="ICollection.IsSynchronized"/>
306
bool ICollection.IsSynchronized
308
get { return InnerHashtable.IsSynchronized; }
312
/// See <see cref="ICollection.SyncRoot"/>
314
object ICollection.SyncRoot
316
get { return InnerHashtable.SyncRoot; }
321
#region Implementation of IEnumerable
324
/// See <see cref="IEnumerable.GetEnumerator"/>
326
IEnumerator IEnumerable.GetEnumerator()
328
return ((IEnumerable)InnerHashtable).GetEnumerator();