Install-Package UriBuilderExtended -Version 1.2.1
dotnet add package UriBuilderExtended --version 1.2.1
<PackageReference Include="UriBuilderExtended" Version="1.2.1" />
paket add UriBuilderExtended --version 1.2.1
#r "nuget: UriBuilderExtended, 1.2.1"
// Install UriBuilderExtended as a Cake Addin #addin nuget:?package=UriBuilderExtended&version=1.2.1 // Install UriBuilderExtended as a Cake Tool #tool nuget:?package=UriBuilderExtended&version=1.2.1
Extensions to .NET's
- Would you like to maintain UriBuilderExtended?
- Alternatively include it in your own library project where it makes sense?
- Are you from microsoft and wants to put this code into UriBuilder?
If you can answer yes to any of these questions, then you are most welcome! I have shifted path and do not work with C# and .NET anymore. Therefore I would like to hand over this project to someone who can keep the code alive.
A thing that is missing from .NET's
System.UriBuilder is a good way to edit the query string. That is what made me look for others solution to this problem, and ultimately made me start this project.
Other good solutions exist that may cover your needs, but I was unable to find one that that covered my requirements:
- Do anything
- Set the query string with support for multiple values
- Be as simple as possible
Install the package from NuGet
using UriBuilderExtended; to your source files, and you will have the following methods available on your
bool HasQuery(string key)
Check for the existence of a query with the given key
bool HasQuery(string key, params string values)
Check for the existence of a query with the given key and the given values
UriBuilder RemoveQuery(string key)
Remove any query with the given key
UriBuilder SetQuery(string key, params string values)
Sets the query parameter for a given key
UriBuilder AddQuery(string key, params string values)
Adds a query parameter for a given key
List<string> GetQueryValues(string key)
Get all values for the given key
UriBuilder builder = new UriBuilder("http://www.mysite.net/"); // URL is now http://www.mysite.net/ // URL string is obtained from builder.Uri.ToString(), not builder.ToString() // as it sometimes renders differently to what you'd expect builder.AddQuery("myKey", "myValue1"); // URL is now http://www.mysite.net/?myKey=myValue1 builder.AddQuery("myOtherKey", "myOtherValue1"); // URL is now http://www.mysite.net/?myKey=myValue1&myOtherKey=myOtherValue1 builder.AddQuery("myKey", "myValue2", "myValue3"); // URL is now http://www.mysite.net/?myKey=myValue1&myKey=myValue2&myKey=myValue3&myOtherKey=myOtherValue1 builder.SetQuery("myKey", "newValue1", "newValue2"); // URL is now http://www.mysite.net/?myOtherKey=myOtherValue1&myKey=newValue1&myKey=newValue2 builder.HasQuery("myKey"); builder.HasQuery("myOtherKey"); // true builder.HasQuery("myKey", "myValue1"); // false builder.HasQuery("myKey", "newValue1"); // true builder.HasQuery("notMymyKey"); // false builder.GetQueryValues("myKey"); // An ICollection containing values "newValue1" and "newValue2"
|.NET Framework||net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48|
This package has no dependencies.
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
Added GetQueryKeys method.
Added GetQueryValues method.
First stable release. Changed version scheme.