UriTemplateTable Klasa

Definicja

Klasa reprezentująca asocjacyjny zestaw UriTemplate obiektów.

public ref class UriTemplateTable
public class UriTemplateTable
type UriTemplateTable = class
Public Class UriTemplateTable
Dziedziczenie
UriTemplateTable

Przykłady

Poniższy kod pokazuje, jak utworzyć obiekt UriTemplateTable, wypełnić go i użyć go do dopasowania względem kandydata Uri.

Uri prefix = new Uri("http://localhost/");

//Create a series of templates
UriTemplate weatherByCity  = new UriTemplate("weather/{state}/{city}");
UriTemplate weatherByCountry = new UriTemplate("weather/{country}/{village}");
UriTemplate weatherByState = new UriTemplate("weather/{state}");
UriTemplate traffic = new UriTemplate("traffic/*");
UriTemplate wildcard = new UriTemplate("*");

//Create a template table
UriTemplateTable table = new UriTemplateTable(prefix);
//Add each template to the table with some associated data
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(weatherByCity, "weatherByCity"));
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(weatherByCountry, "weatherByCountry"));
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(weatherByState, "weatherByState"));
table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(traffic, "traffic"));

table.MakeReadOnly(true);
Console.WriteLine("KeyValuePairs:");
foreach (KeyValuePair<UriTemplate, Object> keyPair in table.KeyValuePairs)
{
    Console.WriteLine($"{keyPair.Key}, {keyPair.Value}");
}

Console.WriteLine();

//Call MatchSingle to retrieve some match results:
ICollection<UriTemplateMatch> results = null;
Uri weatherInSeattle = new Uri("http://localhost/weather/Washington/Seattle");

results = table.Match(weatherInSeattle);
if( results != null)
{
    Console.WriteLine("Matching templates:");
    foreach (UriTemplateMatch match in results)
    {
        Console.WriteLine(match.Template);
    }
}
Dim prefix As New Uri("http://localhost/")

' Create a series of templates
Dim weatherByCity As New UriTemplate("weather/ state}/ city}")
Dim weatherByCountry As New UriTemplate("weather/ country}/ village}")
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 New UriTemplateTable(prefix)
' Add each template to the table with some associated data
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByCity, "weatherByCity"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByCountry, "weatherByCountry"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(weatherByState, "weatherByState"))
table.KeyValuePairs.Add(New KeyValuePair(Of UriTemplate, Object)(traffic, "traffic"))

table.MakeReadOnly(True)
Console.WriteLine("KeyValuePairs:")
For Each keyPair As KeyValuePair(Of UriTemplate, Object) In table.KeyValuePairs
    Console.WriteLine("     0},  1}", keyPair.Key, keyPair.Value)
Next

Console.WriteLine()

' Call MatchSingle to retrieve some match results:
Dim results As System.Collections.Generic.ICollection(Of UriTemplateMatch) = Nothing
Dim weatherInSeattle As Uri = New Uri("http://localhost/weather/Washington/Seattle")

results = table.Match(weatherInSeattle)
If results IsNot Nothing Then
    Console.WriteLine("Matching templates:")
    For Each match As UriTemplateMatch In results
        Console.WriteLine("    0}", match.Template)
    Next
End If

Uwagi

A UriTemplateTable to zestaw asocjacyjny UriTemplate obiektów powiązany z wybranym obiektem. Umożliwia dopasowanie kandydatów do identyfikatorów URI (Uniform Resource Identifiers) względem szablonów w zestawie i pobieranie danych skojarzonych z pasującymi szablonami. Zawartość UriTemplateTable elementu można zmienić do MakeReadOnly(Boolean) momentu wywołania metody , w którym następuje jedno z następujących typów weryfikacji:

  • Gdy MakeReadOnly(Boolean) jest wywoływana funkcja przekazywania false, sprawdza, UriTemplateTable czy tabela nie zawiera wielu szablonów równoważnych strukturalnie. Jeśli znajdzie takie szablony, zgłasza wyjątek. Ten typ weryfikacji jest używany w połączeniu z MatchSingle(Uri) , gdy chcesz upewnić się, że tylko jeden szablon pasuje do przychodzącego identyfikatora URI.

  • Po MakeReadOnly(Boolean) wywołaniu przekazywania w elemencie truemożna stosować wiele szablonów równoważnych strukturalnie w obiekcie UriTemplateTable. Jednak żadne ciągi zapytania w szablonach nie mogą być niejednoznaczne; identyczne ciągi zapytania są dozwolone. Aby uzyskać więcej informacji na temat niejednoznacznych ciągów zapytań, zobacz UriTemplate i UriTemplateTable.

Konstruktory

Nazwa Opis
UriTemplateTable()

Inicjuje nowe wystąpienie klasy UriTemplateTable.

UriTemplateTable(IEnumerable<KeyValuePair<UriTemplate,Object>>)

Inicjuje nowe wystąpienie UriTemplateTable klasy z określoną kolekcją par klucz/wartość.

UriTemplateTable(Uri, IEnumerable<KeyValuePair<UriTemplate,Object>>)

Inicjuje nowe wystąpienie UriTemplateTable klasy przy użyciu określonego adresu podstawowego i kolekcji par klucz/wartość.

UriTemplateTable(Uri)

Inicjuje nowe wystąpienie UriTemplateTable klasy przy użyciu określonego adresu podstawowego.

Właściwości

Nazwa Opis
BaseAddress

Pobiera lub ustawia adres podstawowy dla UriTemplateTable wystąpienia.

IsReadOnly

Pobiera wartość określającą, czy UriTemplateTable parametr jest tylko do odczytu.

KeyValuePairs

Pobiera kolekcję par klucz/wartość, które składają się z UriTemplate obiektów i skojarzonych z nimi danych.

OriginalBaseAddress

Pobiera oryginalny adres podstawowy.

Metody

Nazwa Opis
Equals(Object)

Określa, czy określony obiekt jest równy bieżącemu obiektowi.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Pobiera Type bieżącego wystąpienia.

(Odziedziczone po Object)
MakeReadOnly(Boolean)

UriTemplateTable Wykonuje tylko odczyt.

Match(Uri)

Próbuje dopasować kandydata Uri do .UriTemplateTable

MatchSingle(Uri)

Próbuje dopasować kandydata Uri do .UriTemplateTable

MemberwiseClone()

Tworzy płytkią kopię bieżącego Object.

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy