Langue

UriTemplate.Match(Uri, Uri) Méthode

Définition

Tente de faire correspondre un Uri à un UriTemplate.

public:
 UriTemplateMatch ^ Match(Uri ^ baseAddress, Uri ^ candidate);
public UriTemplateMatch Match(Uri baseAddress, Uri candidate);
member this.Match : Uri * Uri -> UriTemplateMatch
Public Function Match (baseAddress As Uri, candidate As Uri) As UriTemplateMatch

Paramètres

baseAddress
Uri

Adresse de base.

candidate
Uri

À Uri mettre en correspondance avec le modèle.

Retours

Instance.

Exemples

L’exemple suivant montre comment appeler la Match(Uri, Uri) méthode .

UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast={day}");
Uri prefix = new Uri("http://localhost");

Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond?forecast=today");
UriTemplateMatch results = template.Match(prefix, fullUri);

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

if (results != null)
{
    foreach (string variableName in results.BoundVariables.Keys)
    {
        Console.WriteLine("   {0}: {1}", variableName, results.BoundVariables[variableName]);
    }
}
Dim template As UriTemplate = New UriTemplate("weather/{state}/{city}?forecast={day}")
Dim prefix As Uri = New Uri("http://localhost")

Dim fullUri As Uri = New Uri("http://localhost/weather/Washington/Redmond?forecast=today")
Dim results As UriTemplateMatch = template.Match(prefix, fullUri)

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

If results IsNot Nothing Then
    For Each variableName As String In results.BoundVariables.Keys
        Console.WriteLine("   {0}: {1}", variableName, results.BoundVariables(variableName))
    Next
End If

Remarques

Si la correspondance réussit, elle UriTemplateMatch est remplie avec les segments d’URI, les valeurs de variable, les valeurs de chaîne de requête et les segments génériques de l’URI candidat. Si la correspondance échoue, null elle est retournée.

S’applique à