UriTemplateMatch.BoundVariables Propriété

Définition

Obtient la collection BoundVariables pour la correspondance du modèle.

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

Valeur de propriété

NameValueCollection

Instance NameValueCollection qui contient des valeurs de variables du modèle extraites de l'URI pendant la mise en correspondance.

Exemples

Le code suivant montre comment accéder à la propriété BoundVariables.

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)

Remarques

Chaque nom de variable de modèle apparaît sous la forme d’un nom dans cette collection et la valeur liée à cette variable est stockée sous le nom correspondant. Les valeurs de cette collection ont toutes fait l’objet de séquences d’échappement converties en caractères réels. Cette collection de valeurs de noms utilise une recherche qui ne respecte pas la casse lors de la mise en correspondance de noms de variables.

S’applique à