UriTemplateTable 類別

定義

表示一組關聯之 UriTemplate 物件的類別。

public ref class UriTemplateTable
public class UriTemplateTable
type UriTemplateTable = class
Public Class UriTemplateTable
繼承
UriTemplateTable

範例

下列程式碼會示範如何建立 UriTemplateTable 並填入內容,以及如何使用它比對候選 Uri

Uri prefix = new Uri("http://localhost/");

//Create a series of templates
UriTemplate weatherByCity  = new UriTemplate("weather/{state}/{city}");
UriTemplate weatherByCountry = new UriTemplate("weather/{country}/{village}");
UriTemplate weatherByState = new UriTemplate("weather/{state}");
UriTemplate traffic = new UriTemplate("traffic/*");
UriTemplate wildcard = new UriTemplate("*");

//Create a template table
UriTemplateTable table = new UriTemplateTable(prefix);
//Add each template to the table with some associated data
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(weatherByCity, "weatherByCity"));
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(weatherByCountry, "weatherByCountry"));
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(weatherByState, "weatherByState"));
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(traffic, "traffic"));

table.MakeReadOnly(true);
Console.WriteLine("KeyValuePairs:");
foreach (KeyValuePair<UriTemplate, Object> keyPair in table.KeyValuePairs)
{
    Console.WriteLine($"{keyPair.Key}, {keyPair.Value}");
}

Console.WriteLine();

//Call MatchSingle to retrieve some match results:
ICollection<UriTemplateMatch> results = null;
Uri weatherInSeattle = new Uri("http://localhost/weather/Washington/Seattle");

results = table.Match(weatherInSeattle);
if( results != null)
{
    Console.WriteLine("Matching templates:");
    foreach (UriTemplateMatch match in results)
    {
        Console.WriteLine(match.Template);
    }
}
Dim prefix As New Uri("http://localhost/")

' Create a series of templates
Dim weatherByCity As New UriTemplate("weather/ state}/ city}")
Dim weatherByCountry As New UriTemplate("weather/ country}/ village}")
Dim weatherByState As New UriTemplate("weather/ state}")
Dim traffic As New UriTemplate("traffic/*")
Dim wildcard As New UriTemplate("*")

' Create a template table
Dim table As New UriTemplateTable(prefix)
' Add each template to the table with some associated data
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByCity, "weatherByCity"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByCountry, "weatherByCountry"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByState, "weatherByState"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(traffic, "traffic"))

table.MakeReadOnly(True)
Console.WriteLine("KeyValuePairs:")
For Each keyPair As KeyValuePair(Of UriTemplate, Object) In table.KeyValuePairs
    Console.WriteLine("     0},  1}", keyPair.Key, keyPair.Value)
Next

Console.WriteLine()

' Call MatchSingle to retrieve some match results:
Dim results As System.Collections.Generic.ICollection(Of UriTemplateMatch) = Nothing
Dim weatherInSeattle As Uri = New Uri("http://localhost/weather/Washington/Seattle")

results = table.Match(weatherInSeattle)
If results IsNot Nothing Then
    Console.WriteLine("Matching templates:")
    For Each match As UriTemplateMatch In results
        Console.WriteLine("    0}", match.Template)
    Next
End If

備註

UriTemplateTable 是一組關聯的 UriTemplate 物件,這些物件則限制為開發人員所選擇的物件。 它可讓您比對候選的統一資源識別碼 (URI) 和該組物件中的樣板,並擷取與相符樣板關聯的資料。 您可以變更 UriTemplateTable 的內容,直到呼叫 MakeReadOnly(Boolean) 方法為止,此時會進行下列其中一種類型的驗證:

建構函式

UriTemplateTable()

初始化 UriTemplateTable 類別的新執行個體。

UriTemplateTable(IEnumerable<KeyValuePair<UriTemplate,Object>>)

使用指定的索引鍵/值組集合,初始化 UriTemplateTable 類別的新執行個體。

UriTemplateTable(Uri)

使用指定的基底位址,初始化 UriTemplateTable 類別的新執行個體。

UriTemplateTable(Uri, IEnumerable<KeyValuePair<UriTemplate,Object>>)

使用指定的基底位址和索引鍵/值組集合,初始化 UriTemplateTable 類別的新執行個體。

屬性

BaseAddress

取得或設定 UriTemplateTable 執行個體的基底位址 (Base Address)。

IsReadOnly

取得值,這個值會指定 UriTemplateTable 是否為唯讀。

KeyValuePairs

取得包含 UriTemplate 物件及其相關資料的索引鍵/值組集合。

OriginalBaseAddress

取得原始的基底位址。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MakeReadOnly(Boolean)

UriTemplateTable 成為唯讀。

Match(Uri)

嘗試比對候選 UriUriTemplateTable

MatchSingle(Uri)

嘗試比對候選 UriUriTemplateTable

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於