Skip to content

Instantly share code, notes, and snippets.

@mastoj
Created February 19, 2015 09:16
Show Gist options
  • Save mastoj/17b998de8dbfb718388f to your computer and use it in GitHub Desktop.
Save mastoj/17b998de8dbfb718388f to your computer and use it in GitHub Desktop.
CustomDirectRouteProvider with inherited route prefix
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;
}
}
@sean-thorburn
Copy link

if (attributes == null) is always false.

use

if (!attributes.Any())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment