UriTemplateTable.Match Method (Uri)


Attempts to match a candidate Uri to the UriTemplateTable.

Namespace:   System
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

Public Function Match (
	uri As Uri
) As Collection(Of UriTemplateMatch)


Type: System.Uri

The candidate URI.

Return Value

Type: System.Collections.ObjectModel.Collection(Of UriTemplateMatch)

A collection of UriTemplateMatch instances.

This method may return multiple matches.

The following example shows how to call the Match(Uri) method.

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


' 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)
End If

.NET Framework
Available since 3.5
Return to top