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
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
UriThe 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
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
UriThe URI to parse.
key
stringThe parameter key to retrieve.
defaultValue
stringThe 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
UriThe 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
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
UriThe 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
UriThe 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
UriThe 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
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
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
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.