UriTemplateTable Classe

Definição

Uma classe que representa um conjunto associativo de UriTemplate objetos.

public ref class UriTemplateTable
public class UriTemplateTable
type UriTemplateTable = class
Public Class UriTemplateTable
Herança
UriTemplateTable

Exemplos

O código seguinte mostra como criar um UriTemplateTable, preenchê-lo e usá-lo para corresponder a um candidato 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

Observações

A UriTemplateTable é um conjunto associativo de UriTemplate objetos ligados a um objeto escolhido pelo desenvolvedor. Permite-lhe comparar os Identificadores Uniformes de Recursos (URIs) candidatos com os modelos do conjunto e recuperar os dados associados aos modelos correspondentes. O conteúdo de UriTemplateTable pode ser alterado até que o MakeReadOnly(Boolean) método seja chamado, altura em que ocorre um dos seguintes tipos de validação:

  • Quando MakeReadOnly(Boolean) é chamado passing in false, verifica UriTemplateTable se a tabela não contém múltiplos modelos estruturalmente equivalentes. Se encontrar esses modelos, lança uma exceção. Este tipo de validação é usado em conjunto quando MatchSingle(Uri) se quer garantir que apenas um modelo corresponde a um URI recebido.

  • Quando MakeReadOnly(Boolean) é chamado de passagem em true, múltiplos modelos estruturalmente equivalentes podem ser contidos dentro de um UriTemplateTable. No entanto, quaisquer cadeias de consulta nos templates não devem ser ambíguas; Cadeias de consulta idênticas são permitidas. Para mais informações sobre cadeias de consulta ambíguas, veja UriTemplate e UriTemplateTable.

Construtores

Name Description
UriTemplateTable()

Inicializa uma nova instância da UriTemplateTable classe.

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

Inicializa uma nova instância da UriTemplateTable classe com a coleção especificada de pares chave/valor.

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

Inicializa uma nova instância da UriTemplateTable classe com o endereço base especificado e a coleção de pares chave/valor.

UriTemplateTable(Uri)

Inicializa uma nova instância da UriTemplateTable classe com o endereço base especificado.

Propriedades

Name Description
BaseAddress

Obtém ou define o endereço base da UriTemplateTable instância.

IsReadOnly

Obtém um valor que especifica se o UriTemplateTable é apenas leitura.

KeyValuePairs

Obtém uma coleção de pares chave/valor que consistem em UriTemplate objetos e os seus dados associados.

OriginalBaseAddress

Obtém a morada base original.

Métodos

Name Description
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MakeReadOnly(Boolean)

Faz só leitura UriTemplateTable .

Match(Uri)

Tentativas de associar um candidato Uri ao UriTemplateTable.

MatchSingle(Uri)

Tentativas de associar um candidato Uri ao UriTemplateTable.

MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Aplica-se a