Skip to content

Instantly share code, notes, and snippets.

@larsw
Created November 6, 2013 08:16
Show Gist options
  • Select an option

  • Save larsw/7332621 to your computer and use it in GitHub Desktop.

Select an option

Save larsw/7332621 to your computer and use it in GitHub Desktop.
Alternate strategy to match attribute route in HyprLinkr Dispatcher
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