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 的查詢字串名稱/值組都會出現於此集合中,即使它們未明確指定於相符的範本字串中也一樣。 此集合中的值都已經將所有逸出序列轉譯為實際字元。