UriTemplateMatch 類別

定義

表示 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

針對範本比對取得 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)

適用於