Not Serializable
The QueryParamCollection allows developers easy access to the name-value pairs contained in the query portion of a URI.
QueryParamCollection provides a number of utilities to help developers quickly access the names and corresponding values of the query portion in a URI. With this type, one can either determine the value of a query parameter, given a well-known query parameter name, or programmatically iterate through all, passed-in query parameters if the name of a particular query parameter is not known at design-time.
To initialize a QueryParamCollection variable with the query parameters from an incoming GotRequest event, set the InitializeWith property of a variable in the event handler to the event parameter Query.
To read a query parameter in from the QueryParamCollection type, use the .NET indexer syntax on the variable, specifying the name of the query parameter as the argument to the indexer. For example, if one had a variable of the name queryParams, and wanted to know the value of a query parameter called 'user', then the C# snippet queryParams["user"] would resolve to that value.
To programmatically determine all the query parameters passed in, three members defined by QueryParamCollection in particular are of interest. One is the Count property, which will indicate how many query parameters are defined in total. Using that as a loop count, one can then use the GetNameAt( System.Int32 ) method and this[ System.Int32 ] indexer to determine the name and value of each query parameter defined in the request. For example, one can build a CustomCode action that takes a variable named queryParams as an argument, and iterates over every query parameter like the below example:
Example 34.2. Dynamically Determining Contents of the QueryParamCollection
public static string Execute(Metreos.Types.Http.QueryParamCollection queryParams)
{
for(int i = 0; i < queryParams.Count; i++)
{
string queryParamName = queryParams.GetNameAt(i);
string queryParamValue = queryParams[i];
//perform logic...
}
return String.Empty;
}
None.
| .NET Type | Description |
|---|---|
string | Accepts a string that follows the syntax of the query portion of a URI, i.e, '?a=b&c=d'. In common practice this value comes from the Query event parameter of the GotRequest event. |
| Method Name | Description |
|---|---|
| GetNameAt | Retrieves the name of the query parameter at the given index. |
| Reset | Clears the variable to an uninitialized state. |
| Property Name | .NET Type | Description |
|---|---|---|
| Count | System.Int32 | Returns the number of query parameters defined. |
| .NET Indexer Type | .NET Return Type | Description |
|---|---|---|
System.String | System.String | Specify the name of a query parameter of interest. The resulting string is the value of the query parameter. If the name specified does not exist in the query string, then a null is returned. A query parameter that is defined but has no value, such as the 'a' query parameter in this example query portion of an URI: '?a=&b=value', has a value of String.Empty. |
System.Int32 | System.String | Specify the position of the query parameter of interest. The resulting string is the value of the query parameter. If an index is specified that falls ouf of the valid positions in the QueryParamCollection variable, then an unhandled exception will occur and the script instance will halt. |