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
注解
如果匹配成功,则会使用 URI 段、变量值、查询字符串值和候选 URI 的通配符段来填充 UriTemplateMatch。 如果匹配失败,则返回 null
。