UriTemplateMatch UriTemplateMatch UriTemplateMatch UriTemplateMatch Class

定义

一个类,表示对 UriTemplate 实例执行匹配操作的结果。A class that represents the results of a match operation on a UriTemplate instance.

public ref class UriTemplateMatch
public class UriTemplateMatch
type UriTemplateMatch = class
Public Class UriTemplateMatch
继承
UriTemplateMatchUriTemplateMatchUriTemplateMatchUriTemplateMatch

示例

下面的代码演示如何使用 UriTemplateMatch 类。The following code shows how to use the UriTemplateMatch class.

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) 方法的结果。The UriTemplateMatch class represents the results of calling the Match(Uri, Uri) method. 此类不是线程安全的。This class is not thread safe.

构造函数

UriTemplateMatch() UriTemplateMatch() UriTemplateMatch() UriTemplateMatch()

初始化 UriTemplateMatch 类的新实例。Initializes a new instance of the UriTemplateMatch class.

属性

BaseUri BaseUri BaseUri BaseUri

获取或设置模板匹配的基 URI。Gets or sets the base URI for the template match.

BoundVariables BoundVariables BoundVariables BoundVariables

获取模板匹配的 BoundVariables 集合。Gets the BoundVariables collection for the template match.

Data Data Data Data

获取或设置与 UriTemplateMatch 实例关联的对象。Gets or sets the object associated with the UriTemplateMatch instance.

QueryParameters QueryParameters QueryParameters QueryParameters

获取查询字符串参数及其值的集合。Gets a collection of query string parameters and their values.

RelativePathSegments RelativePathSegments RelativePathSegments RelativePathSegments

获取相对路径段的集合。Gets a collection of relative path segments.

RequestUri RequestUri RequestUri RequestUri

获取或设置匹配的 URI。Gets or sets the matched URI.

Template Template Template Template

获取或设置与此 UriTemplateMatch 实例关联的 UriTemplate 实例。Gets or sets the UriTemplate instance associated with this UriTemplateMatch instance.

WildcardPathSegments WildcardPathSegments WildcardPathSegments WildcardPathSegments

获取 URI 模板中由通配符匹配的路径段的集合。Gets a collection of path segments that are matched by a wildcard in the URI template.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于