コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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;
            }
        }
コード例 #3
0
        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("");
        }
コード例 #4
0
 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;
 }
コード例 #5
0
 private string GetActionTemplate(MvcAction actionInfo)
 {
     return(actionInfo.RequestMethod.GetActionTemplate(actionInfo));
 }
コード例 #6
0
 internal MvcActionParameter(MvcAction action, IMethodParameter methodParameter, TypeFactory typeFactory)
     : this(action, methodParameter.Name, methodParameter.ParameterType, methodParameter.Attributes, typeFactory)
 {
     IsOptional = methodParameter.IsOptional;
 }
コード例 #7
0
 public string GetActionTemplate(MvcAction actionInfo) => "";