UriTemplateTable Classe
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
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 a seguir 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
Comentários
Um UriTemplateTable é um conjunto associativo de UriTemplate objetos associados a um objeto de escolha do desenvolvedor. Ele permite que você corresponda os URIs (Uniform Resource Identifiers) candidatos aos modelos no conjunto e recupere os dados associados aos modelos correspondentes. O conteúdo pode UriTemplateTable ser alterado até que o MakeReadOnly(Boolean) método seja chamado, momento em que ocorre um dos seguintes tipos de validação:
Quando MakeReadOnly(Boolean) é chamado de passagem
false, as UriTemplateTable verificações para verificar se a tabela não contém vários modelos estruturalmente equivalentes. Se encontrar esses modelos, ele gerará uma exceção. Esse tipo de validação é usado em conjunto com MatchSingle(Uri) quando você deseja garantir que apenas um modelo corresponda a um URI de entrada.Quando MakeReadOnly(Boolean) é chamado de passagem
true, vários modelos estruturalmente equivalentes podem ser contidos em um UriTemplateTable. No entanto, todas as cadeias de caracteres de consulta nos modelos não devem ser ambíguas; cadeias de caracteres de consulta idênticas são permitidas. Para obter mais informações sobre cadeias de caracteres de consulta ambíguas, consulte UriTemplate e UriTemplateTable.
Construtores
| Nome | Description |
|---|---|
| UriTemplateTable() |
Inicializa uma nova instância da classe UriTemplateTable. |
| 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
| Nome | Description |
|---|---|
| BaseAddress |
Obtém ou define o endereço base da UriTemplateTable instância. |
| IsReadOnly |
Obtém um valor que especifica se o UriTemplateTable valor é somente leitura. |
| KeyValuePairs |
Obtém uma coleção de pares chave/valor que consistem em UriTemplate objetos e seus dados associados. |
| OriginalBaseAddress |
Obtém o endereço base original. |
Métodos
| Nome | Description |
|---|---|
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MakeReadOnly(Boolean) |
Faz a UriTemplateTable leitura somente. |
| Match(Uri) |
Tenta corresponder um candidato Uri ao UriTemplateTable. |
| MatchSingle(Uri) |
Tenta corresponder um candidato Uri ao UriTemplateTable. |
| MemberwiseClone() |
Cria uma cópia superficial do Objectatual. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual. (Herdado de Object) |