Επεξεργασία

Κοινή χρήση μέσω


RouteValueDictionary Constructors

Definition

Initializes a new instance of the RouteValueDictionary class.

Overloads

RouteValueDictionary()

Initializes a new instance of the RouteValueDictionary class that is empty.

RouteValueDictionary(IDictionary<String,Object>)

Initializes a new instance of the RouteValueDictionary class and adds elements from the specified collection.

RouteValueDictionary(Object)

Initializes a new instance of the RouteValueDictionary class and adds values that are based on properties from the specified object.

RouteValueDictionary()

Initializes a new instance of the RouteValueDictionary class that is empty.

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

Remarks

You can add elements to a RouteValueDictionary object by calling the Add method.

See also

Applies to

RouteValueDictionary(IDictionary<String,Object>)

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))

Parameters

dictionary
IDictionary<String,Object>

A collection whose elements are copied to the new collection.

Exceptions

dictionary is null.

dictionary contains one or more duplicate keys.

Remarks

Every key in a RouteValueDictionary object must be unique. The RouteValueDictionary class uses case-insensitive ordinal comparison. For more information, see OrdinalIgnoreCase. A key cannot be null.

See also

Applies to

RouteValueDictionary(Object)

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)

Parameters

values
Object

An object that contains properties that will be added as elements to the new collection.

Examples

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

Remarks

Every key in a RouteValueDictionary object must be unique according to the dictionary's equality comparer. The RouteValueDictionary class uses case-insensitive ordinal comparison. For more information, see OrdinalIgnoreCase. A key cannot be null.

See also

Applies to