PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/log4net/Util/PropertiesDictionary.cs

https://bitbucket.org/VirtualReality/software-testing
C# | 335 lines | 127 code | 35 blank | 173 comment | 3 complexity | b3333697b08837f0db21076406241678 MD5 | raw file
  1#region Apache License
  2//
  3// Licensed to the Apache Software Foundation (ASF) under one or more 
  4// contributor license agreements. See the NOTICE file distributed with
  5// this work for additional information regarding copyright ownership. 
  6// The ASF licenses this file to you under the Apache License, Version 2.0
  7// (the "License"); you may not use this file except in compliance with 
  8// the License. You may obtain a copy of the License at
  9//
 10// http://www.apache.org/licenses/LICENSE-2.0
 11//
 12// Unless required by applicable law or agreed to in writing, software
 13// distributed under the License is distributed on an "AS IS" BASIS,
 14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15// See the License for the specific language governing permissions and
 16// limitations under the License.
 17//
 18#endregion
 19
 20using System;
 21using System.Collections;
 22#if !NETCF
 23using System.Runtime.Serialization;
 24using System.Xml;
 25#endif
 26
 27namespace log4net.Util
 28{
 29	/// <summary>
 30	/// String keyed object map.
 31	/// </summary>
 32	/// <remarks>
 33	/// <para>
 34	/// While this collection is serializable only member 
 35	/// objects that are serializable will
 36	/// be serialized along with this collection.
 37	/// </para>
 38	/// </remarks>
 39	/// <author>Nicko Cadell</author>
 40	/// <author>Gert Driesen</author>
 41#if NETCF
 42	public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, IDictionary
 43#else
 44	[Serializable] public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, ISerializable, IDictionary
 45#endif
 46	{
 47		#region Public Instance Constructors
 48
 49		/// <summary>
 50		/// Constructor
 51		/// </summary>
 52		/// <remarks>
 53		/// <para>
 54		/// Initializes a new instance of the <see cref="PropertiesDictionary" /> class.
 55		/// </para>
 56		/// </remarks>
 57		public PropertiesDictionary()
 58		{
 59		}
 60
 61		/// <summary>
 62		/// Constructor
 63		/// </summary>
 64		/// <param name="propertiesDictionary">properties to copy</param>
 65		/// <remarks>
 66		/// <para>
 67		/// Initializes a new instance of the <see cref="PropertiesDictionary" /> class.
 68		/// </para>
 69		/// </remarks>
 70		public PropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) : base(propertiesDictionary)
 71		{
 72		}
 73
 74		#endregion Public Instance Constructors
 75
 76		#region Private Instance Constructors
 77
 78#if !NETCF
 79		/// <summary>
 80		/// Initializes a new instance of the <see cref="PropertiesDictionary" /> class 
 81		/// with serialized data.
 82		/// </summary>
 83		/// <param name="info">The <see cref="SerializationInfo" /> that holds the serialized object data.</param>
 84		/// <param name="context">The <see cref="StreamingContext" /> that contains contextual information about the source or destination.</param>
 85		/// <remarks>
 86		/// <para>
 87		/// Because this class is sealed the serialization constructor is private.
 88		/// </para>
 89		/// </remarks>
 90		private PropertiesDictionary(SerializationInfo info, StreamingContext context) : base(info, context)
 91		{
 92		}
 93#endif
 94
 95		#endregion Protected Instance Constructors
 96
 97		#region Public Instance Properties
 98
 99		/// <summary>
100		/// Gets or sets the value of the  property with the specified key.
101		/// </summary>
102		/// <value>
103		/// The value of the property with the specified key.
104		/// </value>
105		/// <param name="key">The key of the property to get or set.</param>
106		/// <remarks>
107		/// <para>
108		/// The property value will only be serialized if it is serializable.
109		/// If it cannot be serialized it will be silently ignored if
110		/// a serialization operation is performed.
111		/// </para>
112		/// </remarks>
113		override public object this[string key]
114		{
115			get { return InnerHashtable[key]; }
116			set { InnerHashtable[key] = value; }
117		}
118
119		#endregion Public Instance Properties
120
121		#region Public Instance Methods
122
123		/// <summary>
124		/// Remove the entry with the specified key from this dictionary
125		/// </summary>
126		/// <param name="key">the key for the entry to remove</param>
127		/// <remarks>
128		/// <para>
129		/// Remove the entry with the specified key from this dictionary
130		/// </para>
131		/// </remarks>
132		public void Remove(string key)
133		{
134			InnerHashtable.Remove(key);
135		}
136
137		#endregion Public Instance Methods
138
139		#region Implementation of IDictionary
140
141		/// <summary>
142		/// See <see cref="IDictionary.GetEnumerator"/>
143		/// </summary>
144		/// <returns>an enumerator</returns>
145		/// <remarks>
146		/// <para>
147		/// Returns a <see cref="IDictionaryEnumerator"/> over the contest of this collection.
148		/// </para>
149		/// </remarks>
150		IDictionaryEnumerator IDictionary.GetEnumerator()
151		{
152			return InnerHashtable.GetEnumerator();
153		}
154
155		/// <summary>
156		/// See <see cref="IDictionary.Remove"/>
157		/// </summary>
158		/// <param name="key">the key to remove</param>
159		/// <remarks>
160		/// <para>
161		/// Remove the entry with the specified key from this dictionary
162		/// </para>
163		/// </remarks>
164		void IDictionary.Remove(object key)
165		{
166			InnerHashtable.Remove(key);
167		}
168
169		/// <summary>
170		/// See <see cref="IDictionary.Contains"/>
171		/// </summary>
172		/// <param name="key">the key to lookup in the collection</param>
173		/// <returns><c>true</c> if the collection contains the specified key</returns>
174		/// <remarks>
175		/// <para>
176		/// Test if this collection contains a specified key.
177		/// </para>
178		/// </remarks>
179		bool IDictionary.Contains(object key)
180		{
181			return InnerHashtable.Contains(key);
182		}
183
184		/// <summary>
185		/// Remove all properties from the properties collection
186		/// </summary>
187		/// <remarks>
188		/// <para>
189		/// Remove all properties from the properties collection
190		/// </para>
191		/// </remarks>
192		public override void Clear()
193		{
194			InnerHashtable.Clear();
195		}
196
197		/// <summary>
198		/// See <see cref="IDictionary.Add"/>
199		/// </summary>
200		/// <param name="key">the key</param>
201		/// <param name="value">the value to store for the key</param>
202		/// <remarks>
203		/// <para>
204		/// Store a value for the specified <see cref="String"/> <paramref name="key"/>.
205		/// </para>
206		/// </remarks>
207		/// <exception cref="ArgumentException">Thrown if the <paramref name="key"/> is not a string</exception>
208		void IDictionary.Add(object key, object value)
209		{
210			if (!(key is string))
211			{
212				throw new ArgumentException("key must be a string", "key");
213			}
214			InnerHashtable.Add(key, value);
215		}
216
217		/// <summary>
218		/// See <see cref="IDictionary.IsReadOnly"/>
219		/// </summary>
220		/// <value>
221		/// <c>false</c>
222		/// </value>
223		/// <remarks>
224		/// <para>
225		/// This collection is modifiable. This property always
226		/// returns <c>false</c>.
227		/// </para>
228		/// </remarks>
229		bool IDictionary.IsReadOnly
230		{
231			get { return false; }
232		}
233
234		/// <summary>
235		/// See <see cref="IDictionary.this"/>
236		/// </summary>
237		/// <value>
238		/// The value for the key specified.
239		/// </value>
240		/// <remarks>
241		/// <para>
242		/// Get or set a value for the specified <see cref="String"/> <paramref name="key"/>.
243		/// </para>
244		/// </remarks>
245		/// <exception cref="ArgumentException">Thrown if the <paramref name="key"/> is not a string</exception>
246		object IDictionary.this[object key]
247		{
248			get
249			{
250				if (!(key is string))
251				{
252					throw new ArgumentException("key must be a string", "key");
253				}
254				return InnerHashtable[key];
255			}
256			set
257			{
258				if (!(key is string))
259				{
260					throw new ArgumentException("key must be a string", "key");
261				}
262				InnerHashtable[key] = value;
263			}
264		}
265
266		/// <summary>
267		/// See <see cref="IDictionary.Values"/>
268		/// </summary>
269		ICollection IDictionary.Values
270		{
271			get { return InnerHashtable.Values; }
272		}
273
274		/// <summary>
275		/// See <see cref="IDictionary.Keys"/>
276		/// </summary>
277		ICollection IDictionary.Keys
278		{
279			get { return InnerHashtable.Keys; }
280		}
281
282		/// <summary>
283		/// See <see cref="IDictionary.IsFixedSize"/>
284		/// </summary>
285		bool IDictionary.IsFixedSize
286		{
287			get { return false; }
288		}
289
290		#endregion
291
292		#region Implementation of ICollection
293
294		/// <summary>
295		/// See <see cref="ICollection.CopyTo"/>
296		/// </summary>
297		/// <param name="array"></param>
298		/// <param name="index"></param>
299		void ICollection.CopyTo(Array array, int index)
300		{
301			InnerHashtable.CopyTo(array, index);
302		}
303
304		/// <summary>
305		/// See <see cref="ICollection.IsSynchronized"/>
306		/// </summary>
307		bool ICollection.IsSynchronized
308		{
309			get { return InnerHashtable.IsSynchronized; }
310		}
311
312		/// <summary>
313		/// See <see cref="ICollection.SyncRoot"/>
314		/// </summary>
315		object ICollection.SyncRoot
316		{
317			get { return InnerHashtable.SyncRoot; }
318		}
319
320		#endregion
321
322		#region Implementation of IEnumerable
323
324		/// <summary>
325		/// See <see cref="IEnumerable.GetEnumerator"/>
326		/// </summary>
327		IEnumerator IEnumerable.GetEnumerator()
328		{
329			return ((IEnumerable)InnerHashtable).GetEnumerator();
330		}
331
332		#endregion
333	}
334}
335