UriTemplateTable.MatchSingle(Uri) Metodo

Definizione

Crea una corrispondenza tra un URI Uri candidato e UriTemplateTable.

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

Parametri

uri
Uri

URI candidato.

Restituisce

Istanza unica della classe UriTemplateMatch.

Esempio

Nell'esempio seguente viene illustrato come chiamare il metodo 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())

Commenti

Questo metodo restituisce al massimo una sola corrispondenza. Se viene rilevata più di una corrispondenza, viene generata un'eccezione UriTemplateMatchException.

Si applica a