The Labs \ Source Viewer \ SSCLI \ System.Collections.Specialized \ StringDictionary

  1. //------------------------------------------------------------------------------
  2. // <copyright file="StringDictionary.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. /*
  16. */
  17. namespace System.Collections.Specialized
  18. {
  19.     using System.Runtime.InteropServices;
  20.     using System.Diagnostics;
  21.     using System;
  22.     using System.Collections;
  23.     using System.ComponentModel.Design.Serialization;
  24.     using System.Globalization;
  25.    
  26.     /// <devdoc>
  27.     /// <para>Implements a hashtable with the key strongly typed to be
  28.     /// a string rather than an object. </para>
  29.     /// </devdoc>
  30.     [Serializable()]
  31.     [DesignerSerializer("System.Diagnostics.Design.StringDictionaryCodeDomSerializer, " + AssemblyRef.SystemDesign, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + AssemblyRef.SystemDesign)]
  32.     public class StringDictionary : IEnumerable
  33.     {
  34.        
  35.         internal Hashtable contents = new Hashtable();
  36.        
  37.         /// <devdoc>
  38.         /// <para>Initializes a new instance of the System.Windows.Forms.StringDictionary class.</para>
  39.         /// </devdoc>
  40.         public StringDictionary()
  41.         {
  42.         }
  43.        
  44.        
  45.         /// <devdoc>
  46.         /// <para>Gets the number of key-and-value pairs in the System.Windows.Forms.StringDictionary.</para>
  47.         /// </devdoc>
  48.         public virtual int Count {
  49.             get { return contents.Count; }
  50.         }
  51.        
  52.        
  53.         /// <devdoc>
  54.         /// <para>Indicates whether access to the System.Windows.Forms.StringDictionary is synchronized (thread-safe). This property is
  55.         /// read-only.</para>
  56.         /// </devdoc>
  57.         public virtual bool IsSynchronized {
  58.             get { return contents.IsSynchronized; }
  59.         }
  60.        
  61.         /// <devdoc>
  62.         /// <para>Gets or sets the value associated with the specified key.</para>
  63.         /// </devdoc>
  64.         public virtual string this[string key]
  65.         {
  66.             get {
  67.                 if (key == null) {
  68.                     throw new ArgumentNullException("key");
  69.                 }
  70.                
  71.                 return (string)contents[key.ToLower(CultureInfo.InvariantCulture)];
  72.             }
  73.             set {
  74.                 if (key == null) {
  75.                     throw new ArgumentNullException("key");
  76.                 }
  77.                
  78.                 contents[key.ToLower(CultureInfo.InvariantCulture)] = value;
  79.             }
  80.         }
  81.        
  82.         /// <devdoc>
  83.         /// <para>Gets a collection of keys in the System.Windows.Forms.StringDictionary.</para>
  84.         /// </devdoc>
  85.         public virtual ICollection Keys {
  86.             get { return contents.Keys; }
  87.         }
  88.        
  89.        
  90.         /// <devdoc>
  91.         /// <para>Gets an object that can be used to synchronize access to the System.Windows.Forms.StringDictionary.</para>
  92.         /// </devdoc>
  93.         public virtual object SyncRoot {
  94.             get { return contents.SyncRoot; }
  95.         }
  96.        
  97.         /// <devdoc>
  98.         /// <para>Gets a collection of values in the System.Windows.Forms.StringDictionary.</para>
  99.         /// </devdoc>
  100.         public virtual ICollection Values {
  101.             get { return contents.Values; }
  102.         }
  103.        
  104.         /// <devdoc>
  105.         /// <para>Adds an entry with the specified key and value into the System.Windows.Forms.StringDictionary.</para>
  106.         /// </devdoc>
  107.         public virtual void Add(string key, string value)
  108.         {
  109.             if (key == null) {
  110.                 throw new ArgumentNullException("key");
  111.             }
  112.            
  113.             contents.Add(key.ToLower(CultureInfo.InvariantCulture), value);
  114.         }
  115.        
  116.         /// <devdoc>
  117.         /// <para>Removes all entries from the System.Windows.Forms.StringDictionary.</para>
  118.         /// </devdoc>
  119.         public virtual void Clear()
  120.         {
  121.             contents.Clear();
  122.         }
  123.        
  124.         /// <devdoc>
  125.         /// <para>Determines if the string dictionary contains a specific key</para>
  126.         /// </devdoc>
  127.         public virtual bool ContainsKey(string key)
  128.         {
  129.             if (key == null) {
  130.                 throw new ArgumentNullException("key");
  131.             }
  132.            
  133.             return contents.ContainsKey(key.ToLower(CultureInfo.InvariantCulture));
  134.         }
  135.        
  136.         /// <devdoc>
  137.         /// <para>Determines if the System.Windows.Forms.StringDictionary contains a specific value.</para>
  138.         /// </devdoc>
  139.         public virtual bool ContainsValue(string value)
  140.         {
  141.             return contents.ContainsValue(value);
  142.         }
  143.        
  144.         /// <devdoc>
  145.         /// <para>Copies the string dictionary values to a one-dimensional <see cref='System.Array'/> instance at the
  146.         /// specified index.</para>
  147.         /// </devdoc>
  148.         public virtual void CopyTo(Array array, int index)
  149.         {
  150.             contents.CopyTo(array, index);
  151.         }
  152.        
  153.         /// <devdoc>
  154.         /// <para>Returns an enumerator that can iterate through the string dictionary.</para>
  155.         /// </devdoc>
  156.         public virtual IEnumerator GetEnumerator()
  157.         {
  158.             return contents.GetEnumerator();
  159.         }
  160.        
  161.         /// <devdoc>
  162.         /// <para>Removes the entry with the specified key from the string dictionary.</para>
  163.         /// </devdoc>
  164.         public virtual void Remove(string key)
  165.         {
  166.             if (key == null) {
  167.                 throw new ArgumentNullException("key");
  168.             }
  169.            
  170.             contents.Remove(key.ToLower(CultureInfo.InvariantCulture));
  171.         }
  172.        
  173.     }
  174.    
  175. }

Developer Fusion