diff --git a/CHANGELOG.md b/CHANGELOG.md index 18366b9..e99f693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Added Shim to read a list from xml with no root element + - Added a URI query builder ### Changed - Fixed JSON DateTime parsing in .Net Standard 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