UriTemplateTable.MatchSingle(Uri) Metoda

Definice

Pokusí se spárovat kandidáta Uri s UriTemplateTable.

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

Parametry

uri
Uri

Identifikátor URI kandidáta

Návraty

Jedna UriTemplateMatch instance.

Příklady

Následující příklad ukazuje, jak volat metodu 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())

Poznámky

Tato metoda vrátí maximálně jednu shodu. Pokud se najde více než jedna shoda, vyvolá se UriTemplateMatchException hodnota .

Platí pro