UriTemplateTable.KeyValuePairs 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得包含 UriTemplate 物件及其相關資料的索引鍵/值組集合。
public:
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 物件及其相關資料的索引鍵/值組集合。
範例
下列範例將示範如何存取 KeyValuePairs 屬性。
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();
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)
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()
備註
表中的每個 UriTemplate 執行個體都有與其相關聯的資料。 屬性包含索引鍵/值組集合,其中索引鍵為 執行個體,而值為與 相關聯的資料。 只能在呼叫 KeyValuePairs、MakeReadOnly(Boolean) 或 Match(Uri) 之前新增值至 MatchSingle(Uri) 屬性,否則就會擲回 NotSupportedException。