Beispiel #1
0
        public static string GetActionPath(this ActionDescriptor actionDescriptor)
        {
            var controllerAction = (ControllerActionDescriptor)actionDescriptor;

            var httpMethodMetadata = controllerAction.EndpointMetadata.FirstOrDefault(x => x is HttpMethodMetadata);

            var methods = new List <string>();

            if (httpMethodMetadata != null)
            {
                methods.AddRange(((HttpMethodMetadata)httpMethodMetadata).HttpMethods);
            }

            if (controllerAction.AttributeRouteInfo == null)
            {
                var area       = actionDescriptor.GetAreaName();
                var controller = actionDescriptor.GetControllerName();
                var action     = actionDescriptor.GetActionName();
                var path       = (area == null ? $"{controller}/{action}" : $"{area}/{controller}/{action}").ToLower();
                return($"{methods.ExpandAndToString()} {path}".ToLower());
            }
            else
            {
                var regex    = new Regex("{\\w+}");
                var template = controllerAction.AttributeRouteInfo.Template.ToLower();
                template = regex.Replace(template, "{arg}");
                return($"{methods.ExpandAndToString()} {template}".ToLower());

                ;
            }
        }