UriTemplateMatch.Data 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定與 UriTemplateMatch 執行個體建立關聯的物件。
public:
property System::Object ^ Data { System::Object ^ get(); void set(System::Object ^ value); };
public object Data { get; set; }
member this.Data : obj with get, set
Public Property Data As Object
屬性值
Object 執行個體。
範例
下列程式碼將示範如何存取 Data 屬性。
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)
{
Object data = results.Data;
}
Dim prefix As New Uri("http://localhost/")
' Create some templates:
Dim weatherByCity As New UriTemplate("weather/ state}/ city}")
Dim weatherByState As New UriTemplate("weather/ state}")
Dim traffic As New UriTemplate("traffic/*")
Dim wildcard As New UriTemplate("*")
'Create a template table
Dim table As UriTemplateTable = New UriTemplateTable(prefix)
'Add the templates to the template table along with some associated data
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByCity, "weatherByCity"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByState, "weatherByState"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(traffic, "traffic"))
'Match a URI to a template
Dim candidateUri As New Uri("http://localhost/weather/WA/Redmond")
Dim results As UriTemplateMatch = table.MatchSingle(candidateUri)
If (results IsNot Nothing) Then
'Get the data associated with the matching template
Dim data As String = CType(results.Data, String)
Console.WriteLine("Matching data is 0}", Data)
End If
備註
當您新增 UriTemplate 至 UriTemplateTable 時,您也將資料與範本產生關聯。 此值為應用程式專屬;無特別的語意與此值有關聯。 呼叫 Match(Uri) 並且找到符合的項目,此時比對範本相關聯的資料會在 Data 屬性中傳回。