Export (0) Print
Expand All

UriTemplateTable.KeyValuePairs Property

Gets a collection of key/value pairs that consist of UriTemplate objects and their associated data.

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

public IList<KeyValuePair<UriTemplate, Object>> KeyValuePairs { get; }

Property Value

Type: System.Collections.Generic.IList<KeyValuePair<UriTemplate, Object>>
A collection of key/value pairs that consist of UriTemplate objects and their associated data.

Each UriTemplate instance in the table has data associated with it. The KeyValuePairs property contains a collection of key value pairs where the key is a UriTemplate instance and the value is the data associated with the UriTemplate. Values can only be added to KeyValuePairs property prior to calling MakeReadOnly(Boolean) or Match(Uri) or MatchSingle(Uri) otherwise a NotSupportedException is thrown.

The following example shows how to access the KeyValuePairs property.

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

Console.WriteLine("KeyValuePairs:");
foreach (KeyValuePair<UriTemplate, Object> keyPair in table.KeyValuePairs)
{
    Console.WriteLine("     0},  1}", keyPair.Key, keyPair.Value);
}

Console.WriteLine();

.NET Framework

Supported in: 4.6, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft