fix stackoverflow issues

This commit is contained in:
Tommy Parnell
2016-11-08 20:28:58 -05:00
parent 2ff61218d0
commit 754d7cbff4
3 changed files with 14 additions and 6 deletions

View File

@@ -48,7 +48,7 @@ namespace FluentUriBuilder.Tests
public void TestAddParameterArrayint()
{
var url = new UriBuilder("http://awesome.com")
.WithParameter("awesome", new List<int>() { 1, 2 }.Cast<Object>());
.WithParameter("awesome", new List<int>() { 1, 2 }.Cast<object>());
Assert.Equal("http://awesome.com/?awesome=1,2", url.Uri.ToString());
}

View File

@@ -8,23 +8,23 @@ namespace System
{
public static class TerribleDevUriExtensions
{
public static UriBuilder WithParameter(this UriBuilder bld, string key, params string[] values) => bld.WithParameter(key, values);
public static UriBuilder WithParameter(this UriBuilder bld, string key, params string[] values) => bld.WithParameter(key, valuesEnum: values);
public static UriBuilder WithParameter(this UriBuilder bld, string key, IEnumerable<object> values)
public static UriBuilder WithParameter(this UriBuilder bld, string key, IEnumerable<object> valuesEnum)
{
if(string.IsNullOrWhiteSpace(key))
{
throw new ArgumentNullException(nameof(key));
}
if(values == null)
if(valuesEnum == null)
{
values = new string[0];
valuesEnum = new string[0];
}
var isfirst = string.IsNullOrWhiteSpace(bld.Query);
var intitialValue = isfirst ? "?" : $"{bld.Query}&";
var sb = new StringBuilder($"{intitialValue}{key}");
var validValueHit = false;
foreach(var value in values)
foreach(var value in valuesEnum)
{
var toSValue = value?.ToString();
if(string.IsNullOrWhiteSpace(toSValue)) continue;