UriTemplate.Match(Uri, Uri) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
嘗試比對 Uri 與 UriTemplate。
public:
UriTemplateMatch ^ Match(Uri ^ baseAddress, Uri ^ candidate);
public UriTemplateMatch Match (Uri baseAddress, Uri candidate);
member this.Match : Uri * Uri -> UriTemplateMatch
Public Function Match (baseAddress As Uri, candidate As Uri) As UriTemplateMatch
參數
- baseAddress
- Uri
基底位址。
傳回
執行個體。
範例
下列範例會示範如何呼叫 Match(Uri, Uri) 方法。
UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast={day}");
Uri prefix = new Uri("http://localhost");
Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond?forecast=today");
UriTemplateMatch results = template.Match(prefix, fullUri);
Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());
if (results != null)
{
foreach (string variableName in results.BoundVariables.Keys)
{
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables[variableName]);
}
}
Dim template As UriTemplate = New UriTemplate("weather/{state}/{city}?forecast={day}")
Dim prefix As Uri = New Uri("http://localhost")
Dim fullUri As Uri = New Uri("http://localhost/weather/Washington/Redmond?forecast=today")
Dim results As UriTemplateMatch = template.Match(prefix, fullUri)
Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString())
If results IsNot Nothing Then
For Each variableName As String In results.BoundVariables.Keys
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables(variableName))
Next
End If
備註
如果比對成功,UriTemplateMatch 會從填入候選 URI 的 URI 區段、變數值、查詢字串值和萬用字元區段。 如果比對不成功,則會傳回 null
。