UriTemplateTable.KeyValuePairs 属性


获取由 UriTemplate 对象及其关联数据构成的键/值对集合。Gets a collection of key/value pairs that consist of UriTemplate objects and their associated data.

 property System::Collections::Generic::IList<System::Collections::Generic::KeyValuePair<UriTemplate ^, System::Object ^>> ^ KeyValuePairs { System::Collections::Generic::IList<System::Collections::Generic::KeyValuePair<UriTemplate ^, System::Object ^>> ^ get(); };
public System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<UriTemplate,object>> KeyValuePairs { get; }
member this.KeyValuePairs : System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<UriTemplate, obj>>
Public ReadOnly Property KeyValuePairs As IList(Of KeyValuePair(Of UriTemplate, Object))


一个键/值对的集合,由 UriTemplate 对象及其关联的数据构成。A collection of key/value pairs that consist of UriTemplate objects and their associated data.


下面的示例演示如何访问 KeyValuePairs 属性。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"));


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

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


For Each keyPair As KeyValuePair(Of UriTemplate, Object) In table.KeyValuePairs
    Console.WriteLine("     0},  1}", keyPair.Key, keyPair.Value)



表中每个 UriTemplate 实例都有与之关联的数据。Each UriTemplate instance in the table has data associated with it. KeyValuePairs 属性包含键值对的集合,其中键是 UriTemplate 实例,值是与 UriTemplate 关联的数据。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. 值仅可以在调用 KeyValuePairsMakeReadOnly(Boolean)Match(Uri) 之前添加到 MatchSingle(Uri) 属性,否则会引发 NotSupportedExceptionValues can only be added to KeyValuePairs property prior to calling MakeReadOnly(Boolean) or Match(Uri) or MatchSingle(Uri) otherwise a NotSupportedException is thrown.