Created
November 6, 2013 08:16
-
-
Save larsw/7332621 to your computer and use it in GitHub Desktop.
Alternate strategy to match attribute route in HyprLinkr Dispatcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Rouple Dispatch(MethodCallExpression method, IDictionary<string, object> routeValues) | |
| { | |
| if (method == null) | |
| throw new ArgumentNullException("method"); | |
| var newRouteValues = new Dictionary<string, object>(routeValues); | |
| var controllerName = method | |
| .Object | |
| .Type | |
| .Name | |
| .ToLowerInvariant() | |
| .Replace("controller", ""); | |
| newRouteValues["controller"] = controllerName; | |
| var attributeRoute = method.Method.GetCustomAttributes(true).Cast<HttpRouteAttribute>().FirstOrDefault(); | |
| string routeName = null; | |
| if (attributeRoute != null) | |
| { | |
| var matchedRoute = _httpRequestMessage.GetConfiguration() | |
| .Routes | |
| .FirstOrDefault(x => | |
| (MethodInfo) x.DataTokens["actionMethod"] == method.Method) | |
| as HttpAttributeRoute; | |
| if (matchedRoute != null) routeName = matchedRoute.RouteName; | |
| } | |
| return new Rouple(routeName, newRouteValues); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment