StringDictionary.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Collections.Specialized.StringDictionary.cs
  3. //
  4. // Author:
  5. // Andreas Nahr ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.ComponentModel.Design.Serialization;
  30. namespace System.Collections.Specialized {
  31. #if NET_2_0
  32. [Serializable]
  33. #endif
  34. [DesignerSerializer ("System.Diagnostics.Design.StringDictionaryCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  35. public class StringDictionary : IEnumerable
  36. {
  37. private Hashtable table;
  38. public StringDictionary()
  39. {
  40. table = new Hashtable();
  41. }
  42. // Public Instance Properties
  43. public virtual int Count
  44. {
  45. get {
  46. return table.Count;
  47. }
  48. }
  49. public virtual bool IsSynchronized
  50. {
  51. get {
  52. return false;
  53. }
  54. }
  55. public virtual string this[string key]
  56. {
  57. get {
  58. #if NET_2_0
  59. if (key == null)
  60. throw new ArgumentNullException ("key");
  61. #endif
  62. return (string) table[key.ToLower()];
  63. }
  64. set {
  65. #if NET_2_0
  66. if (key == null)
  67. throw new ArgumentNullException ("key");
  68. #endif
  69. table[key.ToLower()] = value;
  70. }
  71. }
  72. public virtual ICollection Keys
  73. {
  74. get {
  75. return table.Keys;
  76. }
  77. }
  78. public virtual ICollection Values
  79. {
  80. get {
  81. return table.Values;
  82. }
  83. }
  84. public virtual object SyncRoot
  85. {
  86. get {
  87. return table.SyncRoot;
  88. }
  89. }
  90. // Public Instance Methods
  91. public virtual void Add(string key, string value)
  92. {
  93. #if NET_2_0
  94. if (key == null)
  95. throw new ArgumentNullException ("key");
  96. #endif
  97. table.Add(key.ToLower(), value);
  98. }
  99. public virtual void Clear()
  100. {
  101. table.Clear();
  102. }
  103. public virtual bool ContainsKey(string key)
  104. {
  105. #if NET_2_0
  106. if (key == null)
  107. throw new ArgumentNullException ("key");
  108. #endif
  109. return table.ContainsKey(key.ToLower());
  110. }
  111. public virtual bool ContainsValue(string value)
  112. {
  113. return table.ContainsValue(value);
  114. }
  115. public virtual void CopyTo(Array array, int index)
  116. {
  117. table.CopyTo(array, index);
  118. }
  119. public virtual IEnumerator GetEnumerator()
  120. {
  121. return table.GetEnumerator();
  122. }
  123. public virtual void Remove(string key)
  124. {
  125. #if NET_2_0
  126. if (key == null)
  127. throw new ArgumentNullException ("key");
  128. #endif
  129. table.Remove(key.ToLower());
  130. }
  131. }
  132. }