UriTemplate.Match(Uri, Uri) Method

Definition

Attempts to match a Uri to a UriTemplate.

C#
public UriTemplateMatch Match(Uri baseAddress, Uri candidate);

Parameters

baseAddress
Uri

The base address.

candidate
Uri

The Uri to match against the template.

Returns

An instance.

Examples

The following example shows how to call the Match(Uri, Uri) method.

C#
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]);
    }
}

Remarks

If the match is successful the UriTemplateMatch is populated with the URI segments, variable values, query string values, and wildcard segments from the candidate URI. If the match is unsuccessful, null is returned.

Applies to

Ürün Sürümler
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1