UriHelper.WithQueryParameter Method

Namespace
Kampute.DocToolkit.Support
Assembly
  • Kampute.DocToolkit.dll

Definition

Creates a new Uri with the specified query parameter added.
public static Uri WithQueryParameter(this Uri uri, string paramName, string paramValue)

Parameters

uri Uri
The Uri instance to append the query parameter to.
paramName string
The name of the query parameter.
paramValue string
The value of the query parameter, which will be URI-encoded.

Returns

Uri
A new Uri with the query parameter added.

Exceptions

ArgumentNullException
Thrown when uri or paramValue is null.
ArgumentException
Thrown when paramName is null or empty.

Remarks

This method creates a new Uri instance with the specified query parameter added to the original URI. If the original URI already contains a query string with the same parameter name, rather than replacing it, the method appends the new parameter to the existing query string.
The method URI-encodes the parameter name and value. To avoid double encoding, ensure that the parameter name and value are not already URI-encoded.