/// <summary> /// Returns action url from specified expression. /// Use <see cref="From"/> when no matter value is or to get from current request /// </summary> public static string Action <TController>( this IUrlHelper urlHelper, Expression <Func <TController, object> > expression) { var methodCallExpression = RouteHelper.GetInnerMethodCallExpression(expression); var actionDescriptor = urlHelper.ActionContext .HttpContext .RequestServices .GetRequiredService <IActionDescriptorCollectionProvider>() .ActionDescriptors .Items .OfType <ControllerActionDescriptor>() .Single(ad => ad.MethodInfo == methodCallExpression.Method); var actionArguments = RouteHelper.GetActionArguments(actionDescriptor.Parameters, methodCallExpression); return(urlHelper.Action(actionDescriptor.ActionName, actionDescriptor.ControllerName, actionArguments)); }
public IActionRouteBuilder AddRoute <TResult>( string template, Expression <Func <TController, TResult> > expression) { var declaration = new RouteDeclaration(template); services.Configure <RoutingOptions>(options => { var methodCall = RouteHelper.GetInnerMethodCallExpression(expression); foreach (var(info, parameter) in RouteHelper.GetRouteParameters(methodCall)) { options.Parameters.Add(info, parameter); } options.Actions.Add(methodCall.Method, declaration); }); return(new ActionRouteBuilder(declaration)); }