RouteValueDictionary 類別

定義

表示您在路由架構的許多地方使用的索引鍵/值組之不區分大小寫的集合,例如定義路徑的預設值時或產生以路徑為依據的 URL 時。Represents a case-insensitive collection of key/value pairs that you use in various places in the routing framework, such as when you define the default values for a route or when you generate a URL that is based on a route.

public ref class RouteValueDictionary : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>, System::Collections::Generic::IDictionary<System::String ^, System::Object ^>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>
public class RouteValueDictionary : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string,object>>, System.Collections.Generic.IDictionary<string,object>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,object>>
type RouteValueDictionary = class
    interface IDictionary<string, obj>
    interface ICollection<KeyValuePair<string, obj>>
    interface seq<KeyValuePair<string, obj>>
    interface IEnumerable
Public Class RouteValueDictionary
Implements ICollection(Of KeyValuePair(Of String, Object)), IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object))
繼承
RouteValueDictionary
實作

範例

下列範例顯示如何Route建立物件,以及如何Constraints設定、 DataTokensDefaults屬性。The following example shows how to create a Route object and how to set the Constraints, DataTokens, and Defaults properties.

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    Route reportRoute = new Route("{locale}/{year}", new ReportRouteHandler());
    reportRoute.Defaults = new RouteValueDictionary { { "locale", "en-US" }, { "year", DateTime.Now.Year.ToString() } };
    reportRoute.Constraints = new RouteValueDictionary { { "locale", "[a-z]{2}-[a-z]{2}" }, { "year", @"\d{4}" } };
    reportRoute.DataTokens = new RouteValueDictionary { { "format", "short" } };
    routes.Add(reportRoute);
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RegisterRoutes(RouteTable.Routes)
End Sub

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    Dim urlPattern As String
    Dim reportRoute As Route
    
    urlPattern = "{locale}/{year}"
    
    reportRoute = New Route(urlPattern, New ReportRouteHandler)
    reportRoute.Defaults = New RouteValueDictionary(New With {.locale = "en-US", .year = DateTime.Now.Year.ToString()})
    reportRoute.Constraints = New RouteValueDictionary(New With {.locale = "[a-z]{2}-[a-z]{2}", .year = "\d{4}"})
    reportRoute.DataTokens = New RouteValueDictionary(New With {.format = "short"})

    routes.Add(reportRoute)
End Sub

備註

RouteValueDictionary類別可讓您使用 ASP.NET 路由所需的索引鍵/值組集合。The RouteValueDictionary class enables you to work with collections of key/value pairs that are required in order to use ASP.NET routing. 您可以使用RouteValueDictionary物件來定義ConstraintsDataTokensDefaults屬性的值。You use the RouteValueDictionary object to define values for the Constraints, DataTokens, and Defaults properties. 當您藉由RouteValueDictionary GetVirtualPath呼叫方法並傳遞RouteValueDictionary物件做為參數來產生 URL 時,也會使用物件。You also use a RouteValueDictionary object when you generate a URL by calling the GetVirtualPath method and passing a RouteValueDictionary object as a parameter.

物件中的RouteValueDictionary每個索引鍵都必須是唯一的。Every key in a RouteValueDictionary object must be unique. RouteValueDictionary類別使用不區分大小寫的序數比較。The RouteValueDictionary class uses case-insensitive ordinal comparison. 如需詳細資訊,請參閱OrdinalIgnoreCaseFor more information, see OrdinalIgnoreCase. 索引鍵不可以null是。A key cannot be null.

建構函式

RouteValueDictionary()

初始化 RouteValueDictionary 類別的新執行個體,這個執行個體是空白的。Initializes a new instance of the RouteValueDictionary class that is empty.

RouteValueDictionary(IDictionary<String,Object>)

初始化 RouteValueDictionary 類別的新執行個體,並從指定的集合加入項目。Initializes a new instance of the RouteValueDictionary class and adds elements from the specified collection.

RouteValueDictionary(Object)

初始化 RouteValueDictionary 類別的新執行個體,並從指定的物件加入以屬性為依據的值。Initializes a new instance of the RouteValueDictionary class and adds values that are based on properties from the specified object.

屬性

Count

取得集合中的機碼值組數目。Gets the number of key/value pairs that are in the collection.

Item[String]

取得或設定與指定之索引鍵相關聯的值。Gets or sets the value that is associated with the specified key.

Keys

取得集合,其中包含字典中的所有索引鍵。Gets a collection that contains the keys in the dictionary.

Values

取得集合,其中包含字典中的所有值。Gets a collection that contains the values in the dictionary.

方法

Add(String, Object)

使用指定的索引鍵,將指定的值加入字典中。Adds the specified value to the dictionary by using the specified key.

Clear()

從字典移除所有索引鍵和值。Removes all keys and values from the dictionary.

ContainsKey(String)

判斷字典是否包含指定的索引鍵。Determines whether the dictionary contains the specified key.

ContainsValue(Object)

判斷字典是否包含特定值。Determines whether the dictionary contains a specific value.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetEnumerator()

傳回可用來逐一查看字典的列舉值。Returns an enumerator that you can use to iterate through the dictionary.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
Remove(String)

從字典移除有指定之索引鍵的值。Removes the value that has the specified key from the dictionary.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
TryGetValue(String, Object)

取得值,這個值表示某個值是否與指定的索引鍵相關聯。Gets a value that indicates whether a value is associated with the specified key.

明確介面實作

ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>)

如需這個成員的說明,請參閱 Add(T)For a description of this member, see Add(T).

ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>)

如需這個成員的說明,請參閱 Contains(T)For a description of this member, see Contains(T).

ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32)

如需這個成員的說明,請參閱 CopyTo(T[], Int32)For a description of this member, see CopyTo(T[], Int32).

ICollection<KeyValuePair<String,Object>>.IsReadOnly

如需這個成員的說明,請參閱 IsReadOnlyFor a description of this member, see IsReadOnly.

ICollection<KeyValuePair<String,Object>>.Remove(KeyValuePair<String,Object>)

如需這個成員的說明,請參閱 Remove(T)For a description of this member, see Remove(T).

IDictionary<String,Object>.Keys

如需這個成員的說明,請參閱 KeysFor a description of this member, see Keys.

IDictionary<String,Object>.Values

如需這個成員的說明,請參閱 ValuesFor a description of this member, see Values.

IEnumerable.GetEnumerator()

如需這個成員的說明,請參閱 GetEnumerator()For a description of this member, see GetEnumerator().

IEnumerable<KeyValuePair<String,Object>>.GetEnumerator()

如需這個成員的說明,請參閱 GetEnumerator()For a description of this member, see GetEnumerator().

擴充方法

CopyToDataTable<T>(IEnumerable<T>)

根據輸入 DataTable 物件 (其中泛型參數 TDataRow) 傳回包含 IEnumerable<T> 物件複本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>)

傳回包含來源集合中每個節點祖系的項目集合。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName)

傳回包含來源集合中每個節點祖系的已篩選項目集合。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目之子代節點的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>)

傳回包含來源集合中每個項目和文件之子代項目的項目集合。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName)

傳回已篩選的項目集合,其中包含來源集合中每個項目和文件的子代項目。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>)

傳回來源集合中每個項目和文件的子項目集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName)

傳回來源集合中每個項目和文件的已篩選子項目集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>)

傳回包含來源集合中所有節點的節點集合,依據文件順序來排序。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目的子節點集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

在來源集合中,從每一個節點的父節點移除這些節點。Removes every node in the source collection from its parent node.

適用於

另請參閱