UriTemplateTable.Match(Uri) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Crea una corrispondenza tra un URI Uri candidato e UriTemplateTable.
public:
System::Collections::ObjectModel::Collection<UriTemplateMatch ^> ^ Match(Uri ^ uri);
public System.Collections.ObjectModel.Collection<UriTemplateMatch> Match (Uri uri);
member this.Match : Uri -> System.Collections.ObjectModel.Collection<UriTemplateMatch>
Public Function Match (uri As Uri) As Collection(Of UriTemplateMatch)
Parametri
- uri
- Uri
URI candidato.
Restituisce
Raccolta di istanze di UriTemplateMatch.
Esempio
Nell'esempio seguente viene illustrato come chiamare il metodo Match(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 Match 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(" 0}", match.Template);
}
}
Dim prefix As New Uri("http://localhost/")
' Create a series of templates
Dim weatherByCity = New UriTemplate("weather/ state}/ city}")
Dim weatherByCountry = New UriTemplate("weather/ country}/ village}")
Dim weatherByState = New UriTemplate("weather/ state}")
Dim traffic = 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 Match to retrieve some match results:
Dim results As ICollection(Of UriTemplateMatch)
results = Nothing
Dim weatherInSeattle As 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
Commenti
Questo metodo può restituire più corrispondenze.
Si applica a
Collabora con noi su GitHub
L'origine di questo contenuto è disponibile in GitHub, in cui è anche possibile creare ed esaminare i problemi e le richieste pull. Per ulteriori informazioni, vedere la guida per i collaboratori.