UriTemplateMatch.BoundVariables Eigenschaft

Definition

Ruft die BoundVariables-Auflistung für den Vorlagenabgleich ab.

public:
 property System::Collections::Specialized::NameValueCollection ^ BoundVariables { System::Collections::Specialized::NameValueCollection ^ get(); };
public System.Collections.Specialized.NameValueCollection BoundVariables { get; }
member this.BoundVariables : System.Collections.Specialized.NameValueCollection
Public ReadOnly Property BoundVariables As NameValueCollection

Eigenschaftswert

Eine NameValueCollection-Instanz, die Vorlagenvariablenwerte enthält, die während des Abgleichs aus dem URI extrahiert wurden.

Beispiele

Der folgende Code veranschaulicht den Zugriff auf die BoundVariables-Eigenschaft.

UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast=today");
Uri baseAddress = new Uri("http://localhost");
Uri fullUri = new Uri("http://localhost/weather/WA/Seattle?forecast=today");

Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());

// Match a URI to a template
UriTemplateMatch results = template.Match(baseAddress, fullUri);
if (results != null)
{
    // BaseUri
    Console.WriteLine("BaseUri: {0}", results.BaseUri);

    Console.WriteLine("BoundVariables:");
    foreach (string variableName in results.BoundVariables.Keys)
    {
        Console.WriteLine("    {0}: {1}", variableName, results.BoundVariables[variableName]);
    }
}
// Code output:
// BaseUri: http://localhost/
// BoundVariables:
//  state: wa
//  city: seattleConsole.WriteLine("BaseUri: {0}", results.BaseUri);
Dim template As New UriTemplate("weather/ state}/ city}?forecast=today")
Dim baseAddress As New Uri("http://localhost")
Dim fullUri As New Uri("http://localhost/weather/WA/Seattle?forecast=today")

Console.WriteLine("Matching  0} to  1}", template.ToString(), fullUri.ToString())

'Match a URI to a template
Dim results As UriTemplateMatch = template.Match(baseAddress, fullUri)
If (results IsNot Nothing) Then

    'BaseUri
    Console.WriteLine("BaseUri:  0}", results.BaseUri)

    Console.WriteLine("BoundVariables:")
    For Each variableName As String In results.BoundVariables.Keys
        Console.WriteLine("     0}:  1}", variableName, results.BoundVariables(variableName))
    Next
End If
'Code output:
'BaseUri: http://localhost/
'BoundVariables:
' state: wa
' city: seattleConsole.WriteLine("BaseUri:  0}", results.BaseUri)

Hinweise

Jeder Vorlagenvariablenname erscheint als Name in dieser Auflistung, und der an diese Variable gebundene Wert wird unter dem entsprechenden Namen gespeichert. Für die Werte in dieser Auflistung wurden alle Escape-Zeichensequenzen in tatsächliche Zeichen übersetzt. Bei der Suche nach entsprechenden Variablennamen in der Name-/Wert-Auflistung wird nicht zwischen Groß-/Kleinschreibung unterschieden.

Gilt für: