mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 05:05:05 +00:00
feat: Added a URI query builder
This commit is contained in:
@@ -211,6 +211,7 @@
|
|||||||
<Compile Include="Timers\Repeater.cs" />
|
<Compile Include="Timers\Repeater.cs" />
|
||||||
<Compile Include="Timers\SafeTimer.cs" />
|
<Compile Include="Timers\SafeTimer.cs" />
|
||||||
<Compile Include="TryUtils.cs" />
|
<Compile Include="TryUtils.cs" />
|
||||||
|
<Compile Include="UriQueryBuilder.cs" />
|
||||||
<Compile Include="UriUtils.cs" />
|
<Compile Include="UriUtils.cs" />
|
||||||
<Compile Include="Xml\AbstractGenericXmlConverter.cs" />
|
<Compile Include="Xml\AbstractGenericXmlConverter.cs" />
|
||||||
<Compile Include="Xml\AbstractXmlConverter.cs" />
|
<Compile Include="Xml\AbstractXmlConverter.cs" />
|
||||||
|
|||||||
41
ICD.Common.Utils/UriQueryBuilder.cs
Normal file
41
ICD.Common.Utils/UriQueryBuilder.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ICD.Common.Utils
|
||||||
|
{
|
||||||
|
public sealed class UriQueryBuilder
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, string> m_Parameters;
|
||||||
|
|
||||||
|
public UriQueryBuilder()
|
||||||
|
{
|
||||||
|
m_Parameters = new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UriQueryBuilder Append(string key, string value)
|
||||||
|
{
|
||||||
|
m_Parameters.Add(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder builder = new StringBuilder("?");
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
|
foreach (KeyValuePair<string, string> kvp in m_Parameters)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
builder.Append('&');
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
builder.Append(kvp.Key);
|
||||||
|
builder.Append('=');
|
||||||
|
builder.Append(kvp.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user