Пример #1
0
        private void ConfigureSelector(ControllerModel controller, DynamicControllerAttribute controllerAttribute)
        {
            if (_dynamicControllerOptions.UseFriendlyControllerName)
            {
                var suffixsToRemove = _dynamicControllerOptions.RemoveControllerSuffix;
                if (suffixsToRemove != null && suffixsToRemove.Any())
                {
                    suffixsToRemove.ToList().ForEach(suffix => controller.ControllerName = controller.ControllerName.Replace(suffix, ""));
                }
            }

            controller.Selectors.ToList().RemoveAll(selector =>
                                                    selector.AttributeRouteModel == null && (selector.ActionConstraints == null || !selector.ActionConstraints.Any())
                                                    );

            if (controller.Selectors.Any(selector => selector.AttributeRouteModel != null))
            {
                return;
            }

            var areaName = string.Empty;

            if (controllerAttribute != null)
            {
                areaName = controllerAttribute.AreaName;
            }

            controller.Actions.ToList().ForEach(action => ConfigureSelector(areaName, controller.ControllerName, action));
        }
Пример #2
0
 public void Apply(ApplicationModel application)
 {
     foreach (var controller in application.Controllers)
     {
         var controllerType       = controller.ControllerType.AsType();
         var controllerAttributes = controllerType.GetCustomAttributes(typeof(DynamicControllerAttribute), false);
         DynamicControllerAttribute controllerAttribute = null;
         if (controllerAttributes != null && controllerAttributes.Any())
         {
             controllerAttribute = controllerAttributes[0] as DynamicControllerAttribute;
         }
         if (typeof(IDynamicController).IsAssignableFrom(controllerType))
         {
             ConfigureApiExplorer(controller);
             ConfigureSelector(controller, controllerAttribute);
             ConfigureParameters(controller);
         }
     }
 }