Created
February 19, 2015 09:16
-
-
Save mastoj/17b998de8dbfb718388f to your computer and use it in GitHub Desktop.
CustomDirectRouteProvider with inherited route prefix
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 class CustomDirectRouteProvider : DefaultDirectRouteProvider | |
{ | |
protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(HttpActionDescriptor actionDescriptor) | |
{ | |
return actionDescriptor.GetCustomAttributes<IDirectRouteFactory> | |
(inherit: true); | |
} | |
protected override string GetRoutePrefix(HttpControllerDescriptor controllerDescriptor) | |
{ | |
var attributes = controllerDescriptor.GetCustomAttributes<IRoutePrefix>(inherit: true).ToArray(); | |
if (attributes == null) | |
{ | |
return null; | |
} | |
var prefix = attributes[0]; | |
return prefix.Prefix; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if (attributes == null) is always false.
use
if (!attributes.Any())