RouteValueDictionary RouteValueDictionary RouteValueDictionary RouteValueDictionary Class

定义

表示不区分大小写的键/值对的集合,您可以在路由框架中的不同位置(例如,在定义路由的默认值时或在生成基于路由的 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))
继承
RouteValueDictionaryRouteValueDictionaryRouteValueDictionaryRouteValueDictionary
实现

示例

下面的示例演示如何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对象定义ConstraintsDataTokens和属性的值。DefaultsYou use the RouteValueDictionary object to define values for the Constraints, DataTokens, and Defaults properties. 通过RouteValueDictionary RouteValueDictionary调用方法并将对象作为参数传递时,还可以使用对象。 GetVirtualPathYou 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. 键不能为nullA key cannot be null.

构造函数

RouteValueDictionary() RouteValueDictionary() RouteValueDictionary() RouteValueDictionary()

初始化为空的 RouteValueDictionary 类的新实例。Initializes a new instance of the RouteValueDictionary class that is empty.

RouteValueDictionary(IDictionary<String,Object>) RouteValueDictionary(IDictionary<String,Object>) RouteValueDictionary(IDictionary<String,Object>) RouteValueDictionary(IDictionary<String,Object>)

初始化 RouteValueDictionary 类的新实例,并从指定集合添加元素。Initializes a new instance of the RouteValueDictionary class and adds elements from the specified collection.

RouteValueDictionary(Object) RouteValueDictionary(Object) RouteValueDictionary(Object) RouteValueDictionary(Object)

初始化 RouteValueDictionary 类的新实例,并从指定对象添加基于属性的值。Initializes a new instance of the RouteValueDictionary class and adds values that are based on properties from the specified object.

属性

Count Count Count Count

获取集合中键/值对的数目。Gets the number of key/value pairs that are in the collection.

Item[String] Item[String] Item[String] Item[String]

获取或设置与指定的键关联的值。Gets or sets the value that is associated with the specified key.

Keys Keys Keys Keys

获取包含词典中的键的集合。Gets a collection that contains the keys in the dictionary.

Values Values Values Values

获取包含词典中的值的集合。Gets a collection that contains the values in the dictionary.

方法

Add(String, Object) Add(String, Object) Add(String, Object) Add(String, Object)

使用指定键将指定值添加到字典。Adds the specified value to the dictionary by using the specified key.

Clear() Clear() Clear() Clear()

将所有键和值从字典中移除。Removes all keys and values from the dictionary.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

确定字典是否包含指定键。Determines whether the dictionary contains the specified key.

ContainsValue(Object) ContainsValue(Object) ContainsValue(Object) ContainsValue(Object)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回可用于循环访问词典的枚举数。Returns an enumerator that you can use to iterate through the dictionary.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(String) Remove(String) Remove(String) Remove(String)

从词典中移除具有指定键的值。Removes the value that has the specified key from the dictionary.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TryGetValue(String, Object) TryGetValue(String, Object) TryGetValue(String, 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>) ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>) 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>) ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>) 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) ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32) ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32) 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 ICollection<KeyValuePair<String,Object>>.IsReadOnly ICollection<KeyValuePair<String,Object>>.IsReadOnly ICollection<KeyValuePair<String,Object>>.IsReadOnly

有关此成员的说明,请参见 IsReadOnlyFor a description of this member, see IsReadOnly.

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

有关此成员的说明,请参见 Remove(T)For a description of this member, see Remove(T).

IDictionary<String,Object>.Keys IDictionary<String,Object>.Keys IDictionary<String,Object>.Keys IDictionary<String,Object>.Keys

有关此成员的说明,请参见 KeysFor a description of this member, see Keys.

IDictionary<String,Object>.Values IDictionary<String,Object>.Values IDictionary<String,Object>.Values IDictionary<String,Object>.Values

有关此成员的说明,请参见 ValuesFor a description of this member, see Values.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

有关此成员的说明,请参见 GetEnumerator()For a description of this member, see GetEnumerator().

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

有关此成员的说明,请参见 GetEnumerator()For a description of this member, see GetEnumerator().

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 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) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 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) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 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) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) 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) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) 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>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) 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) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) 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>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) 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) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) 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>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) 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>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于

另请参阅