UriTemplateMatch.Data 속성

정의

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

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

설명

UriTemplateUriTemplateTable에 추가할 때 데이터를 템플릿에 연결합니다. 이 값은 애플리케이션별로 다르며 이 값에 특정 의미 체계가 연결되어 있지는 않습니다. Match(Uri)가 호출되고 일치하는 템플릿이 발견되면 해당 템플릿에 연결된 데이터가 Data 속성으로 반환됩니다.

적용 대상