UriTemplateTable Klasa

Definicja

Klasa reprezentująca asocjacyjny UriTemplate zestaw 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ć element 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 asocjacyjny zestaw UriTemplate obiektów powiązany z obiektem wybranego przez dewelopera. 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 jeden z następujących typów weryfikacji:

  • Po MakeReadOnly(Boolean) wywołaniu przekazywania falsesprawdza się, UriTemplateTable czy tabela nie zawiera wielu szablonów równoważnych strukturalnie. Jeśli znajdzie takie szablony, zgłasza wyjątek. Ten typ walidacji 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 trueprogramie można zawierać wiele szablonów strukturalnych równoważnych w obiekcie UriTemplateTable. Jednak wszystkie 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

UriTemplateTable()

Inicjuje nowe wystąpienie klasy UriTemplateTable.

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

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

UriTemplateTable(Uri)

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

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

Inicjuje UriTemplateTable nowe wystąpienie klasy z określonym adresem podstawowym i kolekcją par klucz/wartość.

Właściwości

BaseAddress

Pobiera lub ustawia adres podstawowy dla UriTemplateTable wystąpienia.

IsReadOnly

Pobiera wartość określającą, czy jest tylko UriTemplateTable 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

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

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

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MakeReadOnly(Boolean)

UriTemplateTable Tworzy tylko do odczytu.

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 Objectelementu .

(Odziedziczone po Object)
ToString()

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

(Odziedziczone po Object)

Dotyczy