forked from stevenh/HttpServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IParameterCollection.cs
135 lines (119 loc) · 4.11 KB
/
IParameterCollection.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
using System.Collections;
using System.Collections.Generic;
namespace HttpServer
{
/// <summary>
/// Collection of parameters
/// </summary>
public interface IParameterCollection : IEnumerable<IParameter>
{
/// <summary>
/// Gets number of parameters.
/// </summary>
int Count { get; }
/// <summary>
/// Gets last value of an parameter.
/// </summary>
/// <param name="name">Parameter name</param>
/// <returns>String if found; otherwise <c>null</c>.</returns>
string this[string name] { get; }
/// <summary>
/// Get a parameter.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
IParameter Get(string name);
/// <summary>
/// Add a query string parameter.
/// </summary>
/// <param name="name">Parameter name</param>
/// <param name="value">Value</param>
void Add(string name, string value);
/// <summary>
/// Checks if the specified parameter exists
/// </summary>
/// <param name="name">Parameter name.</param>
/// <returns><c>true</c> if found; otherwise <c>false</c>;</returns>
bool Exists(string name);
}
/// <summary>
/// Parameter in <see cref="IParameterCollection"/>
/// </summary>
public interface IParameter : IEnumerable<string>
{
/// <summary>
/// Gets *last* value.
/// </summary>
/// <remarks>
/// Parameters can have multiple values. This property will always get the last value in the list.
/// </remarks>
/// <value>String if any value exist; otherwise <c>null</c>.</value>
string Value { get; }
/// <summary>
/// Gets or sets name.
/// </summary>
string Name { get; }
/// <summary>
/// Gets a list of all values.
/// </summary>
List<string> Values { get; }
}
/// <summary>
/// A parameter in <see cref="IParameterCollection"/>.
/// </summary>
public class Parameter : IParameter
{
private readonly List<string> _values = new List<string>();
public Parameter(string name, params string[] values)
{
Name = name;
_values.AddRange(values);
}
/// <summary>
/// Gets last value.
/// </summary>
/// <remarks>
/// Parameters can have multiple values. This property will always get the last value in the list.
/// </remarks>
/// <value>String if any value exist; otherwise <c>null</c>.</value>
public string Value
{
get { return _values.Count == 0 ? null : _values[_values.Count - 1]; }
}
/// <summary>
/// Gets or sets name.
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Gets a list of all values.
/// </summary>
public List<string> Values
{
get { return _values; }
}
#region IEnumerable<string> Members
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
/// </returns>
/// <filterpriority>1</filterpriority>
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
return _values.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
/// </returns>
/// <filterpriority>2</filterpriority>
IEnumerator IEnumerable.GetEnumerator()
{
return _values.GetEnumerator();
}
#endregion
}
}