/
StringDictionary.cs
178 lines (153 loc) · 5.72 KB
/
StringDictionary.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel.Design.Serialization;
namespace System.Collections.Specialized
{
/// <devdoc>
/// <para>Implements a hashtable with the key strongly typed to be
/// a string rather than an object. </para>
/// <para>Consider this class obsolete - use Dictionary<String, String> instead
/// with a proper StringComparer instance.</para>
/// </devdoc>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[DesignerSerializer("System.Diagnostics.Design.StringDictionaryCodeDomSerializer, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class StringDictionary : IEnumerable
{
// For compatibility, we want the Keys property to return values in lower-case.
// That means using ToLower in each property on this type. Also for backwards
// compatibility, we will be converting strings to lower-case, which has a
// problem for some Georgian alphabets.
private readonly Hashtable contents = new Hashtable(); // Do not rename (binary serialization)
/// <devdoc>
/// <para>Initializes a new instance of the StringDictionary class.</para>
/// <para>If you're using file names, registry keys, etc, you want to use
/// a Dictionary<String, Object> and use
/// StringComparer.OrdinalIgnoreCase.</para>
/// </devdoc>
public StringDictionary()
{
}
/// <devdoc>
/// <para>Gets the number of key-and-value pairs in the StringDictionary.</para>
/// </devdoc>
public virtual int Count
{
get
{
return contents.Count;
}
}
/// <devdoc>
/// <para>Indicates whether access to the StringDictionary is synchronized (thread-safe). This property is
/// read-only.</para>
/// </devdoc>
public virtual bool IsSynchronized
{
get
{
return contents.IsSynchronized;
}
}
/// <devdoc>
/// <para>Gets or sets the value associated with the specified key.</para>
/// </devdoc>
public virtual string? this[string key]
{
get
{
ArgumentNullException.ThrowIfNull(key);
return (string?)contents[key.ToLowerInvariant()];
}
set
{
ArgumentNullException.ThrowIfNull(key);
contents[key.ToLowerInvariant()] = value;
}
}
/// <devdoc>
/// <para>Gets a collection of keys in the StringDictionary.</para>
/// </devdoc>
public virtual ICollection Keys
{
get
{
return contents.Keys;
}
}
/// <devdoc>
/// <para>Gets an object that can be used to synchronize access to the StringDictionary.</para>
/// </devdoc>
public virtual object SyncRoot
{
get
{
return contents.SyncRoot;
}
}
/// <devdoc>
/// <para>Gets a collection of values in the StringDictionary.</para>
/// </devdoc>
public virtual ICollection Values
{
get
{
return contents.Values;
}
}
/// <devdoc>
/// <para>Adds an entry with the specified key and value into the StringDictionary.</para>
/// </devdoc>
public virtual void Add(string key, string? value)
{
ArgumentNullException.ThrowIfNull(key);
contents.Add(key.ToLowerInvariant(), value);
}
/// <devdoc>
/// <para>Removes all entries from the StringDictionary.</para>
/// </devdoc>
public virtual void Clear()
{
contents.Clear();
}
/// <devdoc>
/// <para>Determines if the string dictionary contains a specific key</para>
/// </devdoc>
public virtual bool ContainsKey(string key)
{
ArgumentNullException.ThrowIfNull(key);
return contents.ContainsKey(key.ToLowerInvariant());
}
/// <devdoc>
/// <para>Determines if the StringDictionary contains a specific value.</para>
/// </devdoc>
public virtual bool ContainsValue(string? value)
{
return contents.ContainsValue(value);
}
/// <devdoc>
/// <para>Copies the string dictionary values to a one-dimensional <see cref='System.Array'/> instance at the
/// specified index.</para>
/// </devdoc>
public virtual void CopyTo(Array array, int index)
{
contents.CopyTo(array, index);
}
/// <devdoc>
/// <para>Returns an enumerator that can iterate through the string dictionary.</para>
/// </devdoc>
public virtual IEnumerator GetEnumerator()
{
return contents.GetEnumerator();
}
/// <devdoc>
/// <para>Removes the entry with the specified key from the string dictionary.</para>
/// </devdoc>
public virtual void Remove(string key)
{
ArgumentNullException.ThrowIfNull(key);
contents.Remove(key.ToLowerInvariant());
}
}
}