UriTemplate.Match(Uri, Uri) UriTemplate.Match(Uri, Uri) UriTemplate.Match(Uri, Uri) UriTemplate.Match(Uri, Uri) Method

定义

Attempts to match a Uri to a UriTemplate.Attempts to match a Uri to a 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 Uri Uri Uri

The base address.The base address.

candidate
Uri Uri Uri Uri

The Uri to match against the template.The Uri to match against the template.

返回

示例

下面的示例演示如何调用 Match(Uri, Uri) 方法。The following example shows how to call the Match(Uri, Uri) method.

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

注解

如果匹配成功,则会使用 URI 段、变量值、查询字符串值和候选 URI 的通配符段来填充 UriTemplateMatchIf the match is successful the UriTemplateMatch is populated with the URI segments, variable values, query string values, and wildcard segments from the candidate URI. 如果匹配失败,则返回 nullIf the match is unsuccessful, null is returned.

适用于