UriBuilderExtended 1.2.1

dotnet add package UriBuilderExtended --version 1.2.1
NuGet\Install-Package UriBuilderExtended -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UriBuilderExtended" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UriBuilderExtended --version 1.2.1
#r "nuget: UriBuilderExtended, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

UriBuilderExtended

Extensions to .NET's System.UriBuilder.

Maintainers wanted!

  • 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.

Introduction

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:

  1. Do anything UriBuilder does
  2. Set the query string with support for multiple values
  3. Be as simple as possible

I have built this with great inspiration from URI.js, which is a very good library for modifying URIs in JavaScript.

Documentation

Install the package from NuGet

Add using UriBuilderExtended; to your source files, and you will have the following methods available on your UriBuilder objects:

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

Examples

    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"
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 39,561 6/1/2016
1.2.0 1,240 6/1/2016
1.1.0 1,212 6/1/2016

1.2.1
     Added GetQueryKeys method.
     
     1.2.0
     Added GetQueryValues method.
     
     1.1.0
     First stable release. Changed version scheme.