private static IList <ControllerActionDescriptor> CreateActionDescriptors(
            ApplicationModel application,
            ControllerModel controller,
            ActionModel action)
        {
            var defaultControllerConstraints      = Enumerable.Empty <IActionConstraintMetadata>();
            var defaultControllerEndpointMetadata = Enumerable.Empty <object>();

            if (controller.Selectors.Count > 0)
            {
                defaultControllerConstraints = controller.Selectors[0].ActionConstraints
                                               .Where(constraint => !(constraint is IRouteTemplateProvider));
                defaultControllerEndpointMetadata = controller.Selectors[0].EndpointMetadata;
            }

            var actionDescriptors = new List <ControllerActionDescriptor>();

            foreach (var result in ActionAttributeRouteModel.GetAttributeRoutes(action))
            {
                var actionSelector     = result.actionSelector;
                var controllerSelector = result.controllerSelector;

                var actionDescriptor = CreateActionDescriptor(action, result.route);
                actionDescriptors.Add(actionDescriptor);
                AddActionFilters(actionDescriptor, action.Filters, controller.Filters, application.Filters);

                var controllerConstraints = defaultControllerConstraints;

                if (controllerSelector?.AttributeRouteModel?.Attribute is IActionConstraintMetadata actionConstraint)
                {
                    // Use the attribute route as a constraint if the controller selector participated in creating this route.
                    controllerConstraints = controllerConstraints.Concat(new[] { actionConstraint });
                }

                AddActionConstraints(actionDescriptor, actionSelector, controllerConstraints);

                // Metadata for the action is more significant so order it before the controller metadata
                var actionDescriptorMetadata = actionSelector.EndpointMetadata.ToList();
                actionDescriptorMetadata.AddRange(defaultControllerEndpointMetadata);

                actionDescriptor.EndpointMetadata = actionDescriptorMetadata;
            }

            return(actionDescriptors);
        }
        private bool ParameterExistsInAnyRoute(ActionModel actionModel, string parameterName)
        {
            foreach (var(route, _, _) in ActionAttributeRouteModel.GetAttributeRoutes(actionModel))
            {
                if (route == null)
                {
                    continue;
                }

                var parsedTemplate = TemplateParser.Parse(route.Template);
                if (parsedTemplate.GetParameter(parameterName) != null)
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool ParameterExistsInAllRoutes(ActionModel actionModel, string parameterName)
        {
            var parameterExistsInSomeRoute = false;

            foreach (var(route, _, _) in ActionAttributeRouteModel.GetAttributeRoutes(actionModel))
            {
                if (route == null)
                {
                    continue;
                }

                var parsedTemplate = TemplateParser.Parse(route.Template);
                if (parsedTemplate.GetParameter(parameterName) == null)
                {
                    return(false);
                }

                // Ensure at least one route exists.
                parameterExistsInSomeRoute = true;
            }

            return(parameterExistsInSomeRoute);
        }