Lenguaje

UriTemplate.Match(Uri, Uri) Método

Definición

Intenta hacer coincidir un Uri objeto con un UriTemplateobjeto .

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

Parámetros

baseAddress
Uri

Dirección base.

candidate
Uri

que Uri se va a comparar con la plantilla.

Devoluciones

Instancia de .

Ejemplos

En el ejemplo siguiente se muestra cómo llamar al Match(Uri, Uri) método .

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

Comentarios

Si la coincidencia se realiza correctamente, UriTemplateMatch se rellena con los segmentos de URI, valores de variable, valores de cadena de consulta y segmentos comodín del URI candidato. Si la coincidencia no se realiza correctamente, null se devuelve.

Se aplica a