public string GenerateRouteTemplate(MvcAction actionInfo) { string area = GetArea(); string routeTemplate = GetBaseRouteTemplate(); if (string.IsNullOrEmpty(routeTemplate)) { routeTemplate = string.IsNullOrEmpty(area) ? ConventionalBaseRouteTemplate : ConventionalBaseRouteTemplateWithArea; } // Append HttpGet, Post, etc route name string actionTemplate = GetActionTemplate(actionInfo); if (!string.IsNullOrEmpty(actionTemplate)) { routeTemplate = AppendSlashIfNecessary(routeTemplate); routeTemplate += actionTemplate; } routeTemplate = PrependBasePath(routeTemplate); routeTemplate = routeTemplate.Replace("[area]", area); // Not a great option for this yet... foreach (var resolver in GetParameterResolvers()) { routeTemplate = resolver.TryResolve(routeTemplate, Controller, actionInfo); } return(routeTemplate); }
/// <summary> /// Creates a new the MVC controllers info /// </summary> /// <param name="namedType">The named type for the controller</param> /// <param name="actionFilter">The parse filter to use for the MVC action attribute</param> /// <param name="typeFactory">The type table</param> internal MvcController(INamedType namedType, TypeFilter actionFilter, TypeFactory typeFactory) { NamedType = namedType; _typeFactory = typeFactory; foreach (IMethod method in namedType.Methods) { if (method.Attributes.Any(attrData => actionFilter.Matches(attrData.AttributeType))) { MvcAction action = new MvcAction(this, method, typeFactory); _actions.Add(action); } } var baseType = NamedType.BaseType; while (baseType != null) { if (baseType.FullName == MvcConstants.ControllerBaseFullName_AspNetCore) { IsAspNetCore = true; break; } baseType = baseType.BaseType; } }
public string GetActionTemplate(MvcAction actionInfo) { var mvcAttr = actionInfo.Attributes.FirstOrDefault(attr => TypeFilter.Matches(attr.AttributeType)); if (mvcAttr.ConstructorArguments.Count > 0) { return(mvcAttr.ConstructorArguments[0] as string); } return(""); }
internal MvcActionParameter(MvcAction action, string paramName, IType memberType, IEnumerable <IAttributeData> memberAttributes, TypeFactory typeFactory) { Action = action; Name = paramName; Types = CompileTypes(memberType, memberAttributes, typeFactory); Attributes = memberAttributes; IsOptional = false; }
private string GetActionTemplate(MvcAction actionInfo) { return(actionInfo.RequestMethod.GetActionTemplate(actionInfo)); }
internal MvcActionParameter(MvcAction action, IMethodParameter methodParameter, TypeFactory typeFactory) : this(action, methodParameter.Name, methodParameter.ParameterType, methodParameter.Attributes, typeFactory) { IsOptional = methodParameter.IsOptional; }
public string GetActionTemplate(MvcAction actionInfo) => "";