UriTemplateTable.MatchSingle(Uri) メソッド

定義

候補 UriUriTemplateTable との照合を試みます。

public:
 UriTemplateMatch ^ MatchSingle(Uri ^ uri);
public UriTemplateMatch MatchSingle (Uri uri);
member this.MatchSingle : Uri -> UriTemplateMatch
Public Function MatchSingle (uri As Uri) As UriTemplateMatch

パラメーター

uri
Uri

候補 URI。

戻り値

UriTemplateMatch

単一の UriTemplateMatch インスタンス。

次の例では、MatchSingle(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);

//Call MatchSingle to retrieve some match results:
Uri weatherInSeattle = new Uri("http://localhost/weather/Washington/Seattle");
UriTemplateMatch match = table.MatchSingle(weatherInSeattle);

Console.WriteLine("Matching template: {0}", match.Template.ToString());
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 = 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)

' Call MatchSingle to retrieve some match results:
Dim weatherInSeattle As New Uri("http://localhost/weather/Washington/Seattle")
Dim match As UriTemplateMatch
match = table.MatchSingle(weatherInSeattle)

Console.WriteLine("Matching template: {0}", match.Template.ToString())

注釈

このメソッドが返す一致は、多くても 1 つです。 複数の一致が見つかると、UriTemplateMatchException がスローされます。

適用対象