Class QueryString
Represents a query string associated with a URL and provides methods to manage its parameters.
public class QueryString : Equatable<QueryString>, IEnumerable<KeyValuePair<string, string>>, IEnumerable
- Inheritance
-
QueryString
- Implements
- Extension Methods
Properties
Count
Gets the number of query parameters.
public int Count { get; }
Property Value
this[string]
Gets or sets the value of the specified query field.
public object this[string queryField] { get; set; }
Parameters
queryField
stringThe query field name.
Property Value
- object
The value of the query field.
Exceptions
- ArgumentNullException
Thrown if the queryField is null or empty.
Raw
Gets the raw query string composed from the key-value pairs.
public string Raw { get; }
Property Value
Url
Gets the URL associated with this query string.
public Url Url { get; }
Property Value
Methods
Append(string, object)
Appends a new query parameter to the query string.
public QueryString Append(string name, object value)
Parameters
Returns
- QueryString
The current instance with the new parameter added.
Exceptions
- ArgumentNullException
Thrown if the name is null or empty, or if the value is null.
Clear()
Clears all the query parameters.
public QueryString Clear()
Returns
- QueryString
The current instance with all query parameters removed.
Clone()
Creates a new instance of QueryString that is a copy of the current instance.
public override QueryString Clone()
Returns
- QueryString
A new instance of QueryString with the same query parameters and URL.
Contains(string)
Checks whether the specified query field exists.
public bool Contains(string queryField)
Parameters
queryField
stringThe query string field name.
Returns
- bool
True if the query field exists; otherwise, false.
GetEnumerator()
Returns an enumerator that iterates through the key-value pairs of the query string.
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, string>>
An enumerator for the query parameters.
GetValue<T>(string)
Retrieves the value of a query parameter converted to the specified type.
public T GetValue<T>(string queryField)
Parameters
queryField
stringThe query field name.
Returns
- T
The converted value of the query parameter.
Type Parameters
T
The type to convert the query parameter value to.
OnEquals(QueryString)
Determines whether the specified QueryString is equal to the current instance.
protected override bool OnEquals(QueryString other)
Parameters
other
QueryStringThe QueryString to compare with the current instance.
Returns
- bool
True if the query strings are equal (ignoring case); otherwise, false.
Remove(string)
Removes a query parameter from the query string.
public QueryString Remove(string name)
Parameters
name
stringThe name of the query parameter to remove.
Returns
- QueryString
The current instance with the parameter removed if it existed.
ToString()
Returns the compiled query string.
public override string ToString()
Returns
- string
The query string as a string.
TryGetValue<T>(string)
Attempts to retrieve the value of a query parameter converted to the specified type. Returns the default value of T if the query parameter is not found.
public T TryGetValue<T>(string queryField)
Parameters
queryField
stringThe query field name.
Returns
- T
The converted value if found; otherwise, the default value of T.
Type Parameters
T
The type to convert the query parameter value to.
TryGetValue<T>(string, T)
Attempts to retrieve the value of a query parameter converted to the specified type. Returns a specified default value if the query parameter is not found.
public T TryGetValue<T>(string queryField, T defaultValue)
Parameters
queryField
stringThe query field name.
defaultValue
TThe default value to return if query parameter is not found.
Returns
- T
The converted value if found; otherwise, the specified default value.
Type Parameters
T
The type to convert the query parameter value to.
TryGetValue<T>(string, out T)
Attempts to retrieve the value of a query parameter converted to the specified type.
public bool TryGetValue<T>(string queryField, out T value)
Parameters
queryField
stringThe query field name.
value
TWhen this method returns, contains the converted value if the query parameter exists; otherwise, the default value of T.
Returns
- bool
True if the query parameter exists and conversion was successful; otherwise, false.
Type Parameters
T
The type to convert the query parameter value to.