UriTemplateMatch.Template 屬性

定義

取得或設定與這個 UriTemplateMatch 執行個體建立關聯的 UriTemplate 執行個體。

public:
 property UriTemplate ^ Template { UriTemplate ^ get(); void set(UriTemplate ^ value); };
public UriTemplate Template { get; set; }
member this.Template : UriTemplate with get, set
Public Property Template As UriTemplate

屬性值

UriTemplate

UriTemplate 執行個體。

範例

下列程式碼將示範如何存取 Template 屬性。

UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast=today");
Uri baseAddress = new Uri("http://localhost");
Uri fullUri = new Uri("http://localhost/weather/WA/Seattle?forecast=today");

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

// Match a URI to a template
UriTemplateMatch results = template.Match(baseAddress, fullUri);
if (results != null)
{
    Console.WriteLine("Template:");
    Console.WriteLine(results.Template);
}
// Code output:
// Template:
// weather/{state}/{city}?forecast=today
Dim template As New UriTemplate("weather/ state}/ city}?forecast=today")
Dim baseAddress As New Uri("http://localhost")
Dim fullUri As New Uri("http://localhost/weather/WA/Seattle?forecast=today")

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

'Match a URI to a template
Dim results As UriTemplateMatch = template.Match(baseAddress, fullUri)
If (results IsNot Nothing) Then
    Console.WriteLine("Template:")
    Console.WriteLine(results.Template)
End If
'Code output:
'Template:
'weather/ state}/ city}?forecast=today

備註

此屬性包含與候選 URI 相符的 UriTemplate

適用於