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 属性会返回与匹配模板关联的数据。