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オブジェクトの連想セットです。 これにより、候補の Uniform Resource Identifier (URI) をセット内のテンプレートと照合し、一致するテンプレートに関連付けられているデータを取得できます。 UriTemplateTableの内容は、MakeReadOnly(Boolean) メソッドが呼び出されるまで変更できます。この時点で、次のいずれかの種類の検証が行われます。

  • falseを渡すMakeReadOnly(Boolean)が呼び出されると、UriTemplateTableは、テーブルに構造上同等のテンプレートが複数含まれていることを確認します。 このようなテンプレートが見つかると、例外がスローされます。 この種類の検証は、1 つのテンプレートのみが受信 URI と一致するようにする場合に、 MatchSingle(Uri) と組み合わせて使用されます。

  • MakeReadOnly(Boolean)true渡しと呼ばれる場合、UriTemplateTable内に複数の構造的に等価なテンプレートを含めることができます。 ただし、テンプレート内のクエリ文字列はあいまいにすることはできません。同じクエリ文字列を使用できます。 あいまいなクエリ文字列の詳細については、「 UriTemplate と UriTemplateTable」を参照してください。

コンストラクター

名前 説明
UriTemplateTable()

UriTemplateTable クラスの新しいインスタンスを初期化します。

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

指定したキーと値のペアのコレクションを使用して、 UriTemplateTable クラスの新しいインスタンスを初期化します。

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

指定したベース アドレスとキーと値のペアのコレクションを使用して、 UriTemplateTable クラスの新しいインスタンスを初期化します。

UriTemplateTable(Uri)

指定したベース アドレスを使用して、 UriTemplateTable クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
BaseAddress

UriTemplateTable インスタンスのベース アドレスを取得または設定します。

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)

適用対象