diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 23c1b99..7939358 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -211,6 +211,7 @@ + diff --git a/ICD.Common.Utils/UriQueryBuilder.cs b/ICD.Common.Utils/UriQueryBuilder.cs new file mode 100644 index 0000000..7b66485 --- /dev/null +++ b/ICD.Common.Utils/UriQueryBuilder.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Text; + +namespace ICD.Common.Utils +{ + public sealed class UriQueryBuilder + { + private readonly Dictionary m_Parameters; + + public UriQueryBuilder() + { + m_Parameters = new Dictionary(); + } + + 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 kvp in m_Parameters) + { + if (!first) + builder.Append('&'); + first = false; + + builder.Append(kvp.Key); + builder.Append('='); + builder.Append(kvp.Value); + } + + return builder.ToString(); + } + } +} \ No newline at end of file