UriTemplateTable.KeyValuePairs Eigenschaft

Definition

Ruft eine Auflistung von Schlüssel-Wert-Paaren ab, die aus UriTemplate-Objekten und deren zugeordneten Daten bestehen.

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

Eigenschaftswert

Eine Auflistung von Schlüssel-Wert-Paaren, die aus UriTemplate-Objekten und deren zugeordneten Daten bestehen.

Beispiele

Im folgenden Beispiel wird der Zugriff auf die KeyValuePairs-Eigenschaft veranschaulicht.

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

Hinweise

Jeder UriTemplate-Instanz in der Tabelle sind Daten zugeordnet. Die KeyValuePairs-Eigenschaft enthält eine Auflistung von Schlüssel-Wert-Paaren, wobei der Schlüssel einer UriTemplate-Instanz und der Wert den einer UriTemplate zugeordneten Daten entspricht. Werte können der KeyValuePairs-Eigenschaft nur vor dem Aufruf von MakeReadOnly(Boolean), Match(Uri) oder MatchSingle(Uri) hinzugefügt werden. Andernfalls wird eine NotSupportedException ausgelöst.

Gilt für: