UriTemplateMatch.QueryParameters 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取查询字符串参数及其值的集合。
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 实例。
示例
下面的代码演示如何访问 QueryParameters 属性。
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 中的所有查询字符串名称/值对都会出现在此集合中,即使没有在匹配的模板字符串中显式指定它们也是如此。 此集合中的值已将所有转义序列转换为实际字符。