This documentation is archived and is not being maintained.

UriTemplateTable Class

A class that represents an associative set of UriTemplate objects.

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

'Declaration
Public Class UriTemplateTable
'Usage
Dim instance As UriTemplateTable

A UriTemplateTable is an associative set of UriTemplate objects bound to an object of the developer's choosing. It allows you to match candidate Uniform Resource Identifiers (URIs) against the templates in the set and retrieve the data associated with the matching templates. The contents of UriTemplateTable can be changed until the MakeReadOnly(Boolean) method is called, at which time one of following types of validation occurs:

  • When MakeReadOnly(Boolean) is called passing in false, the UriTemplateTable checks to make sure the table contains no multiple structurally-equivalent templates. If it finds such templates, it throws an exception. This type of validation is used in conjunction with MatchSingle(Uri) when you want to ensure only one template matches an incoming URI.

  • When MakeReadOnly(Boolean) is called passing in true, multiple structurally-equivalent templates can be contained within a UriTemplateTable. However, any query strings in the templates must not be ambiguous; identical query strings are allowed. For more information about ambiguous query strings, see UriTemplate and UriTemplateTable.

The following code shows how to create a UriTemplateTable, populate it, and use it to match against a candidate Uri.

Dim prefix As Uri = New Uri("http://localhost/")

'Create a series of templates 
Dim weatherByCity As UriTemplate = New UriTemplate("weather/ state}/ city}")
Dim weatherByCountry As UriTemplate = New UriTemplate("weather/ country}/ village}")
Dim weatherByState As UriTemplate = New UriTemplate("weather/ state}")
Dim traffic As UriTemplate = New UriTemplate("traffic/*")
Dim wildcard As UriTemplate = New UriTemplate("*")

'Create a template table 
Dim table As UriTemplateTable = 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)
Console.WriteLine("KeyValuePairs:")
For Each keyPair As KeyValuePair(Of UriTemplate, Object) In table.KeyValuePairs
    Console.WriteLine("     0},  1}", keyPair.Key, keyPair.Value)
Next

Console.WriteLine()

'Call MatchSingle to retrieve some match results: 
Dim results As Collection(Of UriTemplateMatch) = Nothing 
Dim weatherInSeattle As Uri = 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

System.Object
  System.UriTemplateTable

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Show: