UriTemplateTable.MatchSingle(Uri) Metode

Definisi

Mencoba mencocokkan kandidat Uri dengan UriTemplateTable.

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

Parameter

uri
Uri

Kandidat URI.

Mengembalikan

Satu UriTemplateMatch instans.

Contoh

Contoh berikut menunjukkan cara memanggil MatchSingle(Uri) metode .

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())

Keterangan

Metode ini mengembalikan, paling banyak, satu kecocokan. Jika lebih dari satu kecocokan ditemukan, UriTemplateMatchException dilemparkan.

Berlaku untuk