QueryStringUtilities Class
Provides methods for parsing and manipulating query strings.
public static class QueryStringUtilitiesMethods
AddOrReplaceQueryString overloads
AddOrReplaceQueryString(string, IEnumerable<KeyValuePair<string, StringValues>>)
QueryStringUtilities.csAdds or replaces the given query keys and values in the URI.
public static string AddOrReplaceQueryString(string uri, IEnumerable<KeyValuePair<string, StringValues>> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<KeyValuePair<string, StringValues>>- A collection of name value query pairs to set.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddOrReplaceQueryString(string, IEnumerable<KeyValuePair<string, string?>>)
QueryStringUtilities.csAdds or replaces the given query keys and values in the URI.
public static string AddOrReplaceQueryString(string uri, IEnumerable<KeyValuePair<string, string?>> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<KeyValuePair<string, string?>>- A collection of name value query pairs to set.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddOrReplaceQueryString(string, IEnumerable<(string Name, StringValues Value)>)
QueryStringUtilities.csAdds or replaces the given query keys and values in the URI.
public static string AddOrReplaceQueryString(string uri, IEnumerable<(string Name, StringValues Value)> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<(string Name, StringValues Value)>- A collection of name value query pairs to set.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddOrReplaceQueryString(string, IEnumerable<(string Name, string? Value)>)
QueryStringUtilities.csAdds or replaces the given query keys and values in the URI.
public static string AddOrReplaceQueryString(string uri, IEnumerable<(string Name, string? Value)> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<(string Name, string? Value)>- A collection of name value query pairs to set.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddOrReplaceQueryString(string, string, string?)
QueryStringUtilities.csAdds or replaces the given query key and value in the URI.
Parameters
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionnameisnull.
AddQueryString overloads
AddQueryString(string, IDictionary<string, string?>)
QueryStringUtilities.csAppend the given query keys and values to the URI.
public static string AddQueryString(string uri, IDictionary<string, string?> queryString)Parameters
uristring- The base URI.
queryStringIDictionary<string, string?>- A dictionary of query keys and values to append.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddQueryString(string, IEnumerable<KeyValuePair<string, StringValues>>)
QueryStringUtilities.csAppend the given query keys and values to the URI.
public static string AddQueryString(string uri, IEnumerable<KeyValuePair<string, StringValues>> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<KeyValuePair<string, StringValues>>- A collection of query names and values to append.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddQueryString(string, IEnumerable<KeyValuePair<string, string?>>)
QueryStringUtilities.csAppend the given query keys and values to the URI.
public static string AddQueryString(string uri, IEnumerable<KeyValuePair<string, string?>> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<KeyValuePair<string, string?>>- A collection of name value query pairs to append.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddQueryString(string, IEnumerable<(string Name, StringValues Value)>)
QueryStringUtilities.csAppend the given query keys and values to the URI.
public static string AddQueryString(string uri, IEnumerable<(string Name, StringValues Value)> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<(string Name, StringValues Value)>- A collection of query names and values to append.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
AddQueryString(string, IEnumerable<(string Name, string? Value)>?)
QueryStringUtilities.csAppend the given query keys and values to the URI.
public static string AddQueryString(string uri, IEnumerable<(string Name, string? Value)>? queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<(string Name, string? Value)>?- A collection of query names and values to append, or
null.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.
Remarks
Unlike the other overloads, a null queryString returns uri unchanged.
AddQueryString(string, string, string?)
QueryStringUtilities.csAppend the given query key and value to the URI.
Parameters
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionnameisnull.
Remarks
A null value appends nothing, which is how QueryStringUtilities.RemoveQueryString drops a parameter.
ParseNullableQuery(string?)
QueryStringUtilities.csParse a query string into its component key and value parts.
public static QueryStringParameterCollection? ParseNullableQuery(string? queryString)Parameters
queryStringstring?- The raw query string value, with or without the leading '?'.
Returns
QueryStringParameterCollection? A collection of parsed keys and values, null if there are no entries.
ParseQuery(string?)
QueryStringUtilities.csParse a query string into its component key and value parts.
public static QueryStringParameterCollection ParseQuery(string? queryString)Parameters
queryStringstring?- The raw query string value, with or without the leading '?'.
Returns
QueryStringParameterCollection A collection of parsed keys and values.
RemoveQueryString(string, string)
QueryStringUtilities.csRemoves the specified query parameter from the URI.
Parameters
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionnameisnull.
SetQueryString overloads
SetQueryString(string, IEnumerable<KeyValuePair<string, StringValues>>)
QueryStringUtilities.csReplace the query string with the given query key and value.
public static string SetQueryString(string uri, IEnumerable<KeyValuePair<string, StringValues>> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<KeyValuePair<string, StringValues>>- A collection of name value query pairs to set.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.
SetQueryString(string, IEnumerable<KeyValuePair<string, string?>>)
QueryStringUtilities.csReplace the query string with the given query key and value.
public static string SetQueryString(string uri, IEnumerable<KeyValuePair<string, string?>> queryString)Parameters
uristring- The base URI.
queryStringIEnumerable<KeyValuePair<string, string?>>- A collection of name value query pairs to set.
Returns
string The combined result.
Exceptions
ArgumentNullExceptionuriisnull.ArgumentNullExceptionqueryStringisnull.