RouteValueDictionary 构造函数

定义

初始化 RouteValueDictionary 类的新实例。Initializes a new instance of the RouteValueDictionary class.

重载

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.

RouteValueDictionary()

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

public:
 RouteValueDictionary();
public RouteValueDictionary ();
Public Sub New ()

注解

可以通过RouteValueDictionary Add调用方法将元素添加到对象。You can add elements to a RouteValueDictionary object by calling the Add method.

另请参阅

RouteValueDictionary(IDictionary<String,Object>)

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

public:
 RouteValueDictionary(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ dictionary);
public RouteValueDictionary (System.Collections.Generic.IDictionary<string,object> dictionary);
new System.Web.Routing.RouteValueDictionary : System.Collections.Generic.IDictionary<string, obj> -> System.Web.Routing.RouteValueDictionary
Public Sub New (dictionary As IDictionary(Of String, Object))

参数

dictionary
IDictionary<String,Object>

一个集合,其元素被复制到新集合中。A collection whose elements are copied to the new collection.

异常

dictionarynulldictionary is null.

dictionary 包含一个或多个重复键。dictionary contains one or more duplicate keys.

注解

对象中的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(Object)

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

public:
 RouteValueDictionary(System::Object ^ values);
public RouteValueDictionary (object values);
new System.Web.Routing.RouteValueDictionary : obj -> System.Web.Routing.RouteValueDictionary
Public Sub New (values As Object)

参数

values
Object

一个对象,包含将作为元素添加到新集合中的属性。An object that contains properties that will be added as elements to the new collection.

示例

下面的示例演示如何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比较器,对象中的每个键都必须是唯一的。Every key in a RouteValueDictionary object must be unique according to the dictionary's equality comparer. RouteValueDictionary类使用不区分大小写的序号比较。The RouteValueDictionary class uses case-insensitive ordinal comparison. 有关详细信息,请参阅 OrdinalIgnoreCaseFor more information, see OrdinalIgnoreCase. 键不能为nullA key cannot be null.

另请参阅

适用于