UriTemplateMatch 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
一个类,表示对 UriTemplate 实例执行匹配操作的结果。
public ref class UriTemplateMatch
public class UriTemplateMatch
type UriTemplateMatch = class
Public Class UriTemplateMatch
- 继承
-
UriTemplateMatch
示例
下面的代码演示如何使用 UriTemplateMatch 类。
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)
{
// BaseUri
Console.WriteLine("BaseUri: {0}", results.BaseUri);
Console.WriteLine("BoundVariables:");
foreach (string variableName in results.BoundVariables.Keys)
{
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables[variableName]);
}
Console.WriteLine("QueryParameters:");
foreach (string queryName in results.QueryParameters.Keys)
{
Console.WriteLine(" {0} : {1}", queryName, results.QueryParameters[queryName]);
}
Console.WriteLine();
Console.WriteLine("RelativePathSegments:");
foreach (string segment in results.RelativePathSegments)
{
Console.WriteLine(" {0}", segment);
}
Console.WriteLine();
Console.WriteLine("RequestUri:");
Console.WriteLine(results.RequestUri);
Console.WriteLine("Template:");
Console.WriteLine(results.Template);
Console.WriteLine("WildcardPathSegments:");
foreach (string segment in results.WildcardPathSegments)
{
Console.WriteLine(" {0}", segment);
}
Console.WriteLine();
}
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
'BaseUri
Console.WriteLine("BaseUri: {0}", results.BaseUri)
Console.WriteLine("BoundVariables:")
For Each variableName As String In results.BoundVariables.Keys
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables(variableName))
Next
Console.WriteLine("QueryParameters:")
For Each queryName As String In results.QueryParameters.Keys
Console.WriteLine(" {0} : {1}", queryName, results.QueryParameters(queryName))
Next
Console.WriteLine()
Console.WriteLine("RelativePathSegments:")
For Each segment As String In results.RelativePathSegments
Console.WriteLine(" {0}", segment)
Next
Console.WriteLine()
Console.WriteLine("RequestUri:")
Console.WriteLine(results.RequestUri)
Console.WriteLine("Template:")
Console.WriteLine(results.Template)
Console.WriteLine("WildcardPathSegments:")
For Each segment As String In results.WildcardPathSegments
Console.WriteLine(" {0}", segment)
Next
Console.WriteLine()
End If
注解
UriTemplateMatch 类表示调用 Match(Uri, Uri) 方法的结果。 此类不是线程安全的。
构造函数
UriTemplateMatch() |
初始化 UriTemplateMatch 类的新实例。 |
属性
BaseUri |
获取或设置模板匹配的基 URI。 |
BoundVariables |
获取模板匹配的 |
Data |
获取或设置与 UriTemplateMatch 实例关联的对象。 |
QueryParameters |
获取查询字符串参数及其值的集合。 |
RelativePathSegments |
获取相对路径段的集合。 |
RequestUri |
获取或设置匹配的 URI。 |
Template |
获取或设置与此 UriTemplateMatch 实例关联的 UriTemplate 实例。 |
WildcardPathSegments |
获取 URI 模板中由通配符匹配的路径段的集合。 |
方法
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |