Table of Contents

Class UriExtensions

Namespace
Plugin.BaseTypeExtensions
Assembly
Plugin.BaseTypeExtensions.dll

Provides extension methods for Uri manipulation and utility functions.

public static class UriExtensions
Inheritance
UriExtensions
Inherited Members

Methods

AppendPath(Uri, string)

Appends a path segment to the URI.

public static Uri AppendPath(this Uri uri, string path)

Parameters

uri Uri

The base URI.

path string

The path segment to append.

Returns

Uri

A new URI with the appended path.

Exceptions

ArgumentNullException

Thrown when uri or path is null.

AppendQuery(Uri, Dictionary<string, string>)

Appends multiple query parameters to the URI.

public static Uri AppendQuery(this Uri uri, Dictionary<string, string> parameters)

Parameters

uri Uri

The base URI.

parameters Dictionary<string, string>

The parameters to append.

Returns

Uri

A new URI with the appended query parameters.

Exceptions

ArgumentNullException

Thrown when uri or parameters is null.

AppendQuery(Uri, string, string)

Appends a query parameter to the URI.

public static Uri AppendQuery(this Uri uri, string key, string value)

Parameters

uri Uri

The base URI.

key string

The parameter key.

value string

The parameter value.

Returns

Uri

A new URI with the appended query parameter.

Exceptions

ArgumentNullException

Thrown when uri, key, or value is null.

GetQueryParameter(Uri, string, string)

Gets a specific query parameter value from the URI.

public static string GetQueryParameter(this Uri uri, string key, string defaultValue = "")

Parameters

uri Uri

The URI to parse.

key string

The parameter key to retrieve.

defaultValue string

The default value to return if the parameter is not found.

Returns

string

The parameter value or the default value if not found.

Exceptions

ArgumentNullException

Thrown when uri or key is null.

GetQueryParameters(Uri)

Gets all query parameters from the URI as a dictionary.

public static Dictionary<string, string> GetQueryParameters(this Uri uri)

Parameters

uri Uri

The URI to parse.

Returns

Dictionary<string, string>

A dictionary containing all query parameters.

Exceptions

ArgumentNullException

Thrown when uri is null.

HasQueryParameter(Uri, string)

Determines whether the URI contains the specified query parameter.

public static bool HasQueryParameter(this Uri uri, string key)

Parameters

uri Uri

The URI to check.

key string

The parameter key to look for.

Returns

bool

True if the parameter exists; otherwise, false.

Exceptions

ArgumentNullException

Thrown when uri or key is null.

IsLocalhost(Uri)

Determines whether the URI points to localhost.

public static bool IsLocalhost(this Uri uri)

Parameters

uri Uri

The URI to check.

Returns

bool

True if the URI is localhost; otherwise, false.

Exceptions

ArgumentNullException

Thrown when uri is null.

IsSecure(Uri)

Determines whether the URI uses a secure scheme (HTTPS).

public static bool IsSecure(this Uri uri)

Parameters

uri Uri

The URI to check.

Returns

bool

True if the URI uses HTTPS; otherwise, false.

Exceptions

ArgumentNullException

Thrown when uri is null.

RemoveQuery(Uri)

Removes all query parameters from the URI.

public static Uri RemoveQuery(this Uri uri)

Parameters

uri Uri

The URI to modify.

Returns

Uri

A new URI without query parameters.

Exceptions

ArgumentNullException

Thrown when uri is null.

RemoveQuery(Uri, string)

Removes a specific query parameter from the URI.

public static Uri RemoveQuery(this Uri uri, string key)

Parameters

uri Uri

The URI to modify.

key string

The parameter key to remove.

Returns

Uri

A new URI without the specified query parameter.

Exceptions

ArgumentNullException

Thrown when uri or key is null.

SetPort(Uri, int)

Sets the port of the URI.

public static Uri SetPort(this Uri uri, int port)

Parameters

uri Uri

The URI to modify.

port int

The new port number.

Returns

Uri

A new URI with the specified port.

Exceptions

ArgumentNullException

Thrown when uri is null.

ArgumentOutOfRangeException

Thrown when port is not between 1 and 65535.

SetScheme(Uri, string)

Sets the scheme of the URI.

public static Uri SetScheme(this Uri uri, string scheme)

Parameters

uri Uri

The URI to modify.

scheme string

The new scheme (e.g., "https", "http").

Returns

Uri

A new URI with the specified scheme.

Exceptions

ArgumentNullException

Thrown when uri or scheme is null.

ArgumentException

Thrown when scheme is empty or whitespace.