diff --git a/UriBulider.Fluent.png b/UriBulider.Fluent.png new file mode 100644 index 0000000..c2eabc1 Binary files /dev/null and b/UriBulider.Fluent.png differ diff --git a/src/UriBuilder.Fluent.UnitTests/ThrowsTests.cs b/src/UriBuilder.Fluent.UnitTests/ThrowsTests.cs index 1e7b67a..07bec03 100644 --- a/src/UriBuilder.Fluent.UnitTests/ThrowsTests.cs +++ b/src/UriBuilder.Fluent.UnitTests/ThrowsTests.cs @@ -17,7 +17,7 @@ namespace FluentUriBuilder.Tests Assert.Throws(() => tstObj.WithPathSegment(null)); Assert.Throws(() => tstObj.WithScheme(null)); Assert.Throws(() => tstObj.WithHost(null)); - Assert.Throws(() => tstObj.WithParameter(parameterDictionary: null)); + Assert.Throws(() => tstObj.WithParameter((IEnumerable>) null)); Assert.Throws(() => tstObj.WithFragment(fragmentDictionary: null)); Assert.Throws(() => tstObj.WithPort(-1)); UriBuilder nullPtr = null; diff --git a/src/UriBuilder.Fluent.UnitTests/UriBuilder.Fluent.UnitTests.csproj b/src/UriBuilder.Fluent.UnitTests/UriBuilder.Fluent.UnitTests.csproj index 4111cb6..171cb50 100644 --- a/src/UriBuilder.Fluent.UnitTests/UriBuilder.Fluent.UnitTests.csproj +++ b/src/UriBuilder.Fluent.UnitTests/UriBuilder.Fluent.UnitTests.csproj @@ -1,6 +1,6 @@  - netcoreapp2.0;net461 + net480;net60;net70 diff --git a/src/UriBuilder.Fluent/TerribleDevUriExtensions.cs b/src/UriBuilder.Fluent/TerribleDevUriExtensions.cs index eb04cc8..00dc527 100644 --- a/src/UriBuilder.Fluent/TerribleDevUriExtensions.cs +++ b/src/UriBuilder.Fluent/TerribleDevUriExtensions.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace System { - public static class TerribleDevUriExtensions + public static partial class TerribleDevUriExtensions { /// /// Appends a query string parameter with a key, and many values. Multiple values will be comma seperated. If only 1 value is passed and its null or value, the key will be added to the QS. @@ -17,21 +17,25 @@ namespace System /// public static UriBuilder WithParameter(this UriBuilder bld, string key, params string[] values) => bld.WithParameter(key, valuesEnum: values); + /// - /// Appends query strings from dictionary + /// Appends query strings from a list of key-value pairs (usually a dictionary). /// /// /// /// /// - public static UriBuilder WithParameter(this UriBuilder bld, IDictionary parameterDictionary) + public static UriBuilder WithParameter(this UriBuilder bld, IEnumerable> parameterDictionary) { - if(bld == null) + if (bld == null) { throw new ArgumentNullException(nameof(bld)); } - if(parameterDictionary == null) throw new ArgumentNullException(nameof(parameterDictionary)); - foreach(var item in parameterDictionary) + if (parameterDictionary == null) + { + throw new ArgumentNullException(nameof(parameterDictionary)); + } + foreach (var item in parameterDictionary) { bld.WithParameter(item.Key, item.Value); } @@ -86,7 +90,10 @@ namespace System { throw new ArgumentNullException(nameof(bld)); } - if(fragmentDictionary == null) throw new ArgumentNullException(nameof(fragmentDictionary)); + if (fragmentDictionary == null) + { + throw new ArgumentNullException(nameof(fragmentDictionary)); + } foreach(var item in fragmentDictionary) { bld.WithFragment(item.Key, item.Value); @@ -133,7 +140,10 @@ namespace System { throw new ArgumentNullException(nameof(bld)); } - if(port < 1) throw new ArgumentOutOfRangeException(nameof(port)); + if(port < 1) + { + throw new ArgumentOutOfRangeException(nameof(port)); + } bld.Port = port; return bld; } @@ -149,7 +159,10 @@ namespace System { throw new ArgumentNullException(nameof(bld)); } - if (bld.Uri.IsDefaultPort) bld.Port = -1; + if (bld.Uri.IsDefaultPort) + { + bld.Port = -1; + } return bld; } @@ -188,7 +201,10 @@ namespace System { throw new ArgumentNullException(nameof(bld)); } - if(string.IsNullOrWhiteSpace(scheme)) throw new ArgumentNullException(nameof(scheme)); + if (string.IsNullOrWhiteSpace(scheme)) + { + throw new ArgumentNullException(nameof(scheme)); + } bld.Scheme = scheme; return bld; } @@ -206,7 +222,10 @@ namespace System { throw new ArgumentNullException(nameof(bld)); } - if(string.IsNullOrWhiteSpace(host)) throw new ArgumentNullException(nameof(host)); + if (string.IsNullOrWhiteSpace(host)) + { + throw new ArgumentNullException(nameof(host)); + } bld.Host = host; return bld; } diff --git a/src/UriBuilder.Fluent/TerribleDevUriExtensions_NetCore.cs b/src/UriBuilder.Fluent/TerribleDevUriExtensions_NetCore.cs new file mode 100644 index 0000000..84a8142 --- /dev/null +++ b/src/UriBuilder.Fluent/TerribleDevUriExtensions_NetCore.cs @@ -0,0 +1,34 @@ +#if NET6_0_OR_GREATER + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace System +{ + public static partial class TerribleDevUriExtensions + { + /// + /// Appends query strings from dictionary + /// + /// + /// + /// + /// + public static UriBuilder WithParameter(this UriBuilder bld, IEnumerable<(string, string)> parameterDictionary) + { + if (bld == null) { + throw new ArgumentNullException(nameof(bld)); + } + if (parameterDictionary == null) throw new ArgumentNullException(nameof(parameterDictionary)); + foreach (var item in parameterDictionary) { + bld.WithParameter(item.Item1, item.Item2); + } + return bld; + } + } +} + +#endif \ No newline at end of file diff --git a/src/UriBuilder.Fluent/UriBuilder.Fluent.csproj b/src/UriBuilder.Fluent/UriBuilder.Fluent.csproj index 9102a5d..3d1a665 100644 --- a/src/UriBuilder.Fluent/UriBuilder.Fluent.csproj +++ b/src/UriBuilder.Fluent/UriBuilder.Fluent.csproj @@ -2,21 +2,38 @@ Tommy Parnell - netstandard1.1;net40;net45;netstandard2.0 + net480;net60;net70 UriBuilder.Fluent UriBuilder.Fluent Url building;Uri;Uri building;fluent;extension https://github.com/TerribleDev/UriBuilder.Fluent + + 7.0.0.0 + 7.0.0.0 + 7.0.0 + UriBulider.Fluent.png + - + - - - - + + + This package adds extension methods over System.UriBuilder to help deal with query string parameters and create more of a fluent interface. + Unlike other projects, this NetStandardLibrary compliant package builds ontop of trusty UriBuilder, does not use custom Uri generators, and has no outside dependencies! + + True + True + + + + + + + +