Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<MvcProjectUpgradeChecked>true</MvcProjectUpgradeChecked>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -230,6 +231,9 @@
<Name>AttributeRouting</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Views\ApiExplorer\Index1.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Mvc;
using System.Web.Http;
using AttributeRouting.Web.Http;

namespace AttributeRouting.Tests.Web.Controllers
Expand All @@ -8,7 +8,8 @@ namespace AttributeRouting.Tests.Web.Controllers
public class ApiExplorerController : Controller
{
[GET("")]
public ActionResult Index()
[System.Web.Mvc.ActionName("Index")]
public ActionResult Index101()
{
var explorer = GlobalConfiguration.Configuration.Services.GetApiExplorer();
return View(explorer);
Expand Down
34 changes: 34 additions & 0 deletions src/AttributeRouting.Tests.Web/Views/ApiExplorer/Index1.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@model System.Web.Http.Description.IApiExplorer

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<title>API Explorer (Index 1)</title>
<style type="text/css">
body { font: 14px/1.5em helvetica, arial, sans-serif; }
strong { font-size: 1.25em; }
li { margin-bottom: 10px; }
</style>
</head>
<body>
<div>
<ul>
@foreach (var api in Model.ApiDescriptions)
{
<li>
<strong>@api.HttpMethod @api.RelativePath</strong>
@foreach(var param in api.ParameterDescriptions)
{
<p>Parameter: @param.Name (@param.Source)</p>
}
</li>
}
</ul>
</div>
</body>
</html>
22 changes: 22 additions & 0 deletions src/AttributeRouting.Web.Mvc/RouteAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using System.Web.Mvc;
using AttributeRouting.Helpers;
using System.Collections.Generic;

namespace AttributeRouting.Web.Mvc
{
Expand All @@ -12,6 +13,15 @@ namespace AttributeRouting.Web.Mvc
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class RouteAttribute : ActionMethodSelectorAttribute, IRouteAttribute
{
//private static readonly SortedSet<string> Members =
// new SortedSet<string>(
// typeof(RouteAttribute).GetProperties()
// .Where(p => p.CanRead)
// .Select(p => p.Name),
// StringComparer.CurrentCultureIgnoreCase);

//private static readonly FastMember.TypeAccessor Accessor = FastMember.TypeAccessor.Create(typeof(RouteAttribute));

/// <summary>
/// Specify the route information for an action.
/// The route URL will be the name of the action.
Expand Down Expand Up @@ -132,5 +142,17 @@ public override bool IsValidForRequest(ControllerContext controllerContext, Meth

return HttpMethods.Any(m => m.ValueEquals(httpMethod));
}

public string ActionName { get; set; }

//public object this[string name]
//{
// get
// {
// if(Members.Contains(name))
// { return Accessor[this, name]; }
// return null;
// }
//}
}
}
12 changes: 7 additions & 5 deletions src/AttributeRouting.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.20827.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{38404E6F-56AC-458E-B0A6-3620FEA10A5C}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
Expand Down Expand Up @@ -34,10 +36,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AttributeRouting.Web.Http", "AttributeRouting.Web.Http\AttributeRouting.Web.Http.csproj", "{CCDE9AD7-3822-4B0B-AA19-DF6698A85D3D}"
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Expand Down Expand Up @@ -146,4 +144,8 @@ Global
{486087C6-E95B-4FE2-8263-7B6B2DF81888} = {840281A8-8870-417F-9B24-ED0E866608A2}
{0D2A13E6-A092-402E-B8FE-035F3A620B86} = {840281A8-8870-417F-9B24-ED0E866608A2}
EndGlobalSection
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions src/AttributeRouting/AttributeRouting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
<AssemblyOriginatorKeyFile>AttributeRouting.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="FastMember">
<HintPath>..\packages\FastMember.Signed.1.0.0.11\lib\net40\FastMember.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -119,6 +125,7 @@
</ItemGroup>
<ItemGroup>
<None Include="AttributeRouting.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
37 changes: 20 additions & 17 deletions src/AttributeRouting/Framework/AttributeReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AttributeRouting.Helpers;
using AttributeRouting.Helpers;
using System.Diagnostics;

namespace AttributeRouting.Framework
{
Expand All @@ -29,7 +30,7 @@ public IEnumerable<RouteSpecification> BuildRouteSpecifications()
var controllerCount = 0; // needed to increment controller index
var inheritActionsFromBaseController = _configuration.InheritActionsFromBaseController;

var specs =
var specs = (
// Each controller
from controllerType in _configuration.OrderedControllerTypes
let controllerIndex = controllerCount++
Expand All @@ -50,7 +51,7 @@ from routePrefixAttribute in routePrefixAttributes.DefaultIfEmpty(null).Take(rou
// Build the specification
select new RouteSpecification
{
ActionMethod = actionMethod,
ActionMethod = actionMethod,
ActionName = actionName,
ActionPrecedence = GetSortableOrder(routeAttribute.ActionPrecedence),
AppendTrailingSlash = routeAttribute.AppendTrailingSlashFlag,
Expand All @@ -69,32 +70,34 @@ from routePrefixAttribute in routePrefixAttributes.DefaultIfEmpty(null).Take(rou
PreserveCaseForUrlParameters = routeAttribute.PreserveCaseForUrlParametersFlag,
RouteName = routeAttribute.RouteName,
RoutePrefixUrl = GetRoutePrefixUrl(routePrefixAttribute, controllerType),
RoutePrefixUrlTranslationKey = routePrefixAttribute.SafeGet(a => a.TranslationKey),
RoutePrefixUrlTranslationKey = routePrefixAttribute.SafeGet(a => a.TranslationKey),
RouteUrl = routeAttribute.RouteUrl ?? actionName,
RouteUrlTranslationKey = routeAttribute.TranslationKey,
SitePrecedence = GetSortableOrder(routeAttribute.SitePrecedence),
Subdomain = subdomain,
UseLowercaseRoute = routeAttribute.UseLowercaseRouteFlag,
};
}).ToArray();

// Return specs ordered by route precedence:
return specs.OrderBy(x => x.SitePrecedence)
.ThenBy(x => x.ControllerIndex)
.ThenBy(x => x.PrefixPrecedence)
.ThenBy(x => x.ControllerPrecedence)
.ThenBy(x => x.ActionPrecedence);
}

private static string GetActionName(MethodInfo actionMethod, bool isAsyncController)
{
var actionName = actionMethod.Name;

if (isAsyncController && actionName.EndsWith("Async"))
{
actionName = actionName.Substring(0, actionName.Length - 5);
}

return actionName;
}

private static string GetActionName(MethodInfo actionMethod, bool isAsyncController)
{
// added support for ActionName attribute
var anAttribute = actionMethod.GetCustomAttributes<Attribute>(false).FirstOrDefault(a => a.GetType().Name == "ActionNameAttribute");
var actionName = anAttribute == null ? actionMethod.Name : (string)FastMember.ObjectAccessor.Create(anAttribute)["Name"];

if (isAsyncController && actionName.EndsWith("Async"))
{
actionName = actionName.Substring(0, actionName.Length - 5);
}

return actionName;
}

private static IEnumerable<IRouteAttribute> GetRouteAttributes(MethodInfo actionMethod, RouteConventionAttributeBase convention)
Expand Down
5 changes: 5 additions & 0 deletions src/AttributeRouting/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FastMember.Signed" version="1.0.0.11" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
</packages>