UriTemplate.Match(Uri, Uri) Metoda

Definice

Pokusí se shodovat s Uri .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

Parametry

baseAddress
Uri

Základní adresa.

candidate
Uri

Shoda Uri se šablonou.

Návraty

Instance.

Příklady

Následující příklad ukazuje, jak volat metodu Match(Uri, Uri) .

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

Poznámky

Pokud je shoda úspěšná UriTemplateMatch , naplní se segmenty identifikátoru URI, hodnoty proměnných, řetězcové hodnoty dotazu a segmenty se zástupnými znaky z kandidátového identifikátoru URI. Pokud je shoda neúspěšná, null vrátí se.

Platí pro