Repository navigation
Expand file tree
/
Copy pathNameValueCollection.cs
More file actions
78 lines (67 loc) · 1.88 KB
/
Copy pathNameValueCollection.cs
File metadata and controls
78 lines (67 loc) · 1.88 KB
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
using System;
using System.Linq;
using System.Collections.Generic;
namespace System.Collections.Specialized
{
public class NameValueCollection : List<KeyValuePair<string, string>>
{
public new string this[int index]
{
get
{
return base[index].Value;
}
set
{
var oldKey = base[index].Key;
base[index] = new KeyValuePair<string, string>(oldKey, value);
}
}
public string this[string name]
{
get
{
return this.SingleOrDefault(kv => kv.Key.Equals(name)).Value;
}
set
{
for (var i = 0; i < this.Count; i++)
{
if (name.Equals(this[i], StringComparison.OrdinalIgnoreCase))
{
this.RemoveAt(i);
break;
}
}
this.Add(new KeyValuePair<string, string>(name, value));
}
}
public NameValueCollection()
{
}
public NameValueCollection(int capacity)
: base(capacity)
{
}
public void Add(string name, string value)
{
List<KeyValuePair<string, string>> list = this;
for (int i = Count - 1; i >= 0; --i)
{
if (string.Equals(list[i].Key, name))
{
list[i] = new KeyValuePair<string, string>(name, list[i].Value + "," + value);
return;
}
}
Add(new KeyValuePair<string, string>(name, value));
}
public IEnumerable<string> AllKeys
{
get
{
return this.Select(pair => pair.Key);
}
}
}
}