UriTemplateMatch.Data Właściwość

Definicja

Pobiera lub ustawia obiekt skojarzony z UriTemplateMatch wystąpieniem.Gets or sets the object associated with the UriTemplateMatch instance.

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

Wartość właściwości

Object

ObjectWystąpienie.An Object instance.

Przykłady

Poniższy kod pokazuje, jak uzyskać dostęp do Data właściwości.The following code shows how to access the Data property.

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

Uwagi

Dodanie UriTemplate do UriTemplateTable skojarzenia danych z szablonem.When you add a UriTemplate to a UriTemplateTable you associate data with the template. Ta wartość jest specyficzna dla aplikacji; żadna określona semantyka nie jest skojarzona z tą wartością.This value is application specific; no particular semantics are associated with this value. Gdy Match(Uri) jest wywoływana i zostanie znalezione dopasowanie, dane skojarzone z pasującym szablonem są zwracane we Data właściwości.When Match(Uri) is called and a match is found the data associated with the matching template is returned in the Data property.

Dotyczy