views:

74

answers:

1

How can I merge this two class to one?

this:

new { action = "index|new|edit" }
new { controller = "category|article" }

To this:

new { action = "index|new|edit", controller = "category|article" }

I know that it's not trivial at all, but here is the problem.

I have a method that I used to register my routes. The method don't have controller property in the constrains but I want it to have in few cases, so I want to be able to send a constraint object as a parameter and merge it with the default constratins.

As controller = "" not acceptable and controller = (string)null throw an exception, it seems that we have a problem n the routing system.

I think the best solution is to have something like that:

new RouteValueDictionary(new {
    httpMethod = new HttpMethodConstraint("GET"), 
    id = idValidationRegex ?? MatchAny,
    action = "show", 
    **controller = string.IsNullOrEmpty(controllerConstrains) ?
        ConstraintParameter.NotDefiend :
        controllerConstrains** }),

Thanks.

A: 

I may be misunderstanding the question. Assuming you have two anonymous classes:

var x = new { action = "index|new|edit" }
var y = new { controller = "category|article" }

You can combine them with yet another anonymous class:

var z = new { action = x.action, controller = y.controller };
Kivin