UriTemplateMatch.QueryParameters 属性

定义

获取查询字符串参数及其值的集合。Gets a collection of query string parameters and their values.

public:
 property System::Collections::Specialized::NameValueCollection ^ QueryParameters { System::Collections::Specialized::NameValueCollection ^ get(); };
public System.Collections.Specialized.NameValueCollection QueryParameters { get; }
member this.QueryParameters : System.Collections.Specialized.NameValueCollection
Public ReadOnly Property QueryParameters As NameValueCollection

属性值

一个包含查询字符串参数及其值的 NameValueCollection 实例。A NameValueCollection instance that contains the query string parameters and their values.

示例

下面的代码演示如何访问 QueryParameters 属性。The following code shows how to access the QueryParameters property.

UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast=today");
Uri baseAddress = new Uri("http://localhost");
Uri fullUri = new Uri("http://localhost/weather/WA/Seattle?forecast=today");

Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());

// Match a URI to a template
UriTemplateMatch results = template.Match(baseAddress, fullUri);
if (results != null)
{
    Console.WriteLine("QueryParameters:");
    foreach (string queryName in results.QueryParameters.Keys)
    {
        Console.WriteLine("    {0} : {1}", queryName, results.QueryParameters[queryName]);
    }
    Console.WriteLine();
}
// Code output:
//  QueryParameters:
//  forecast : today
Dim template As New UriTemplate("weather/ state}/ city}?forecast=today")
Dim baseAddress As New Uri("http://localhost")
Dim fullUri As New Uri("http://localhost/weather/WA/Seattle?forecast=today")

Console.WriteLine("Matching  0} to  1}", template.ToString(), fullUri.ToString())

'Match a URI to a template
Dim results As UriTemplateMatch = template.Match(baseAddress, fullUri)
If (results IsNot Nothing) Then

    Console.WriteLine("QueryParameters:")
    For Each queryName As String In results.QueryParameters.Keys
        Console.WriteLine("     0} :  1}", queryName, results.QueryParameters(queryName))
    Next
    Console.WriteLine()
End If
'Code output:
' QueryParameters:
' forecast : today

注解

原始 URI 中的所有查询字符串名称/值对都会出现在此集合中,即使没有在匹配的模板字符串中显式指定它们也是如此。All query string name/value pairs from the original URI appear in this collection, even if they are not explicitly specified in the template string that was matched. 此集合中的值已将所有转义序列转换为实际字符。The values in this collection have been had all escape sequences translated into actual characters.

适用于