Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 2a64299

Browse files
committed
Added comments in the QueryString helper class
1 parent 31ebd6a commit 2a64299

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

Api/Helpers/QueryStringBuilder.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55

66
namespace KoenZomers.OneDrive.Api.Helpers
77
{
8+
/// <summary>
9+
/// Helper class for building querystrings
10+
/// </summary>
811
public class QueryStringBuilder
912
{
13+
/// <summary>
14+
/// Collection of parameters in the querystring
15+
/// </summary>
1016
private readonly Dictionary<string, string> _parameters = new Dictionary<string, string>();
1117

18+
/// <summary>
19+
/// Boolean indicating if the querystring has any items in it
20+
/// </summary>
1221
public bool HasKeys
1322
{
1423
get
@@ -17,12 +26,26 @@ public bool HasKeys
1726
}
1827
}
1928

29+
/// <summary>
30+
/// Character to start the querystring with. Defaults to not including it.
31+
/// </summary>
2032
public char? StartCharacter { get; set; }
2133

34+
/// <summary>
35+
/// Character used to separate the items in the querystring. Defaults to &.
36+
/// </summary>
2237
public char SeperatorCharacter { get; set; }
2338

39+
/// <summary>
40+
/// Character used to separate the keys from its value sin the querystring. Defaults to =.
41+
/// </summary>
2442
public char KeyValueJoinCharacter { get; set; }
2543

44+
/// <summary>
45+
/// Allows retrieval or setting the value of items in the querystring
46+
/// </summary>
47+
/// <param name="key"></param>
48+
/// <returns></returns>
2649
public string this[string key]
2750
{
2851
get
@@ -35,6 +58,9 @@ public string this[string key]
3558
}
3659
}
3760

61+
/// <summary>
62+
/// Collection with keys of the parameters in this querystring
63+
/// </summary>
3864
public string[] Keys
3965
{
4066
get
@@ -43,38 +69,67 @@ public string[] Keys
4369
}
4470
}
4571

72+
/// <summary>
73+
/// Instantiates a new empty querystring
74+
/// </summary>
4675
public QueryStringBuilder()
4776
{
4877
StartCharacter = new char?();
4978
SeperatorCharacter = '&';
5079
KeyValueJoinCharacter = '=';
5180
}
5281

53-
public QueryStringBuilder(string key, string value)
82+
/// <summary>
83+
/// Instantiates a new querystring and adds the provided key and value to it
84+
/// </summary>
85+
/// <param name="key">Key to add</param>
86+
/// <param name="value">Value to add</param>
87+
public QueryStringBuilder(string key, string value) : this()
5488
{
5589
this[key] = value;
5690
}
5791

92+
/// <summary>
93+
/// Removes all items from the querystring
94+
/// </summary>
5895
public void Clear()
5996
{
6097
_parameters.Clear();
6198
}
6299

100+
/// <summary>
101+
/// Returns a boolean indicating if a specific key exists in the querystring
102+
/// </summary>
103+
/// <param name="key">Name of the key to validate if it exists</param>
104+
/// <returns>Boolean indicating if the provided key exists in the querystring</returns>
63105
public bool ContainsKey(string key)
64106
{
65107
return _parameters.ContainsKey(key);
66108
}
67109

110+
/// <summary>
111+
/// Adds an item to the querystring
112+
/// </summary>
113+
/// <param name="key">Key of the item to add</param>
114+
/// <param name="value">Value of the item to add</param>
68115
public void Add(string key, string value)
69116
{
70117
_parameters[key] = value;
71118
}
72119

120+
/// <summary>
121+
/// Removes a specific key from the querystring
122+
/// </summary>
123+
/// <param name="key"></param>
73124
public void Remove(string key)
74125
{
75126
_parameters.Remove(key);
76127
}
77128

129+
/// <summary>
130+
/// Outputs the entire querystring
131+
/// </summary>
132+
/// <returns>Querystring</returns>
78133
public override string ToString()
79134
{
80135
var stringBuilder = new StringBuilder();
@@ -90,7 +145,7 @@ public override string ToString()
90145
{
91146
int num = stringBuilder[stringBuilder.Length - 1];
92147
char? startCharacter = StartCharacter;
93-
if ((num != (int)startCharacter.GetValueOrDefault() ? 1 : (!startCharacter.HasValue ? 1 : 0)) != 0)
148+
if ((num != startCharacter.GetValueOrDefault() ? 1 : (!startCharacter.HasValue ? 1 : 0)) != 0)
94149
stringBuilder.Append(SeperatorCharacter);
95150
}
96151
stringBuilder.Append(keyValuePair.Key);

0 commit comments

Comments
 (0)