UriTemplate.Match(Uri, Uri) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Tenta associar a Uri a a um 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
Parâmetros
- baseAddress
- Uri
A morada da base.
Devoluções
Um exemplo.
Exemplos
O exemplo seguinte mostra como chamar o 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
Observações
Se a correspondência for bem-sucedida, é UriTemplateMatch preenchido com os segmentos URI, valores das variáveis, valores das cadeias de consulta e segmentos curinga do URI candidato. Se a correspondência não for bem-sucedida, null é devolvida.