This commit is contained in:
Tommy Parnell
2016-11-08 13:07:58 -05:00
parent 18455d8358
commit 480403e3af
2 changed files with 33 additions and 14 deletions

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FluentUriBuilder
{
public class Class1
{
public Class1()
{
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System
{
public static class TerribleDevUriExtensions
{
public static void WithParameter(this UriBuilder bld, string key, string value)
{
if(!string.IsNullOrWhiteSpace(bld.Query))
{
bld.Query += $"&{key}={value}";
return;
}
bld.Query = $"{key}={value}";
}
public static void WithParameter(this UriBuilder bld, string key, IEnumerable<object> values)
{
var isfirst = string.IsNullOrWhiteSpace(bld.Query);
var intitialValue = isfirst ? "?" : "&";
var sb = new StringBuilder($"{intitialValue}{key}=");
foreach(var value in values)
{
sb.Append($"{value.ToString()},");
}
bld.Query = sb.ToString().TrimEnd(',');
}
}
}