UriTemplateTable Kelas

Definisi

Kelas yang mewakili sekumpulan UriTemplate objek asosiatif.

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

Contoh

Kode berikut menunjukkan cara membuat UriTemplateTable, mengisinya, dan menggunakannya untuk mencocokkan dengan kandidat 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

Keterangan

UriTemplateTable adalah sekumpulan UriTemplate objek asosiatif yang terikat pada objek yang dipilih pengembang. Ini memungkinkan Anda untuk mencocokkan kandidat Pengidentifikasi Sumber Daya Seragam (URI) terhadap templat dalam set dan mengambil data yang terkait dengan templat yang cocok. Konten UriTemplateTable dapat diubah sampai MakeReadOnly(Boolean) metode dipanggil, pada saat itu salah satu jenis validasi berikut terjadi:

  • Ketika MakeReadOnly(Boolean) disebut passing in false, UriTemplateTable pemeriksaan untuk memastikan tabel tidak berisi beberapa templat yang setara secara struktural. Jika menemukan templat tersebut, templat akan melemparkan pengecualian. Jenis validasi ini digunakan bersama dengan ketika Anda ingin memastikan hanya satu templat yang cocok dengan MatchSingle(Uri) URI masuk.

  • Ketika MakeReadOnly(Boolean) disebut meneruskan , beberapa templat yang setara secara struktural dapat dimuat dalam trueUriTemplateTable. Namun, setiap string kueri dalam templat tidak boleh ambigu; string kueri identik diizinkan. Untuk informasi selengkapnya tentang string kueri ambigu, lihat UriTemplate dan UriTemplateTable.

Konstruktor

Nama Deskripsi
UriTemplateTable()

Menginisialisasi instans baru dari kelas UriTemplateTable.

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

Menginisialisasi instans UriTemplateTable baru kelas dengan kumpulan pasangan kunci/nilai yang ditentukan.

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

Menginisialisasi instans UriTemplateTable baru kelas dengan alamat dasar dan kumpulan pasangan kunci/nilai yang ditentukan.

UriTemplateTable(Uri)

Menginisialisasi instans UriTemplateTable baru kelas dengan alamat dasar yang ditentukan.

Properti

Nama Deskripsi
BaseAddress

Mendapatkan atau mengatur alamat dasar untuk UriTemplateTable instans.

IsReadOnly

Mendapatkan nilai yang menentukan apakah UriTemplateTable hanya dibaca.

KeyValuePairs

Mendapatkan kumpulan pasangan kunci/nilai yang terdiri UriTemplate dari objek dan data terkaitnya.

OriginalBaseAddress

Mendapatkan alamat dasar asli.

Metode

Nama Deskripsi
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
MakeReadOnly(Boolean)

Membuat baca saja UriTemplateTable .

Match(Uri)

Mencoba mencocokkan kandidat Uri dengan UriTemplateTable.

MatchSingle(Uri)

Mencoba mencocokkan kandidat Uri dengan UriTemplateTable.

MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk