public RouteTranslationBuilder TranslateController(string template) { IRouteProcessor routeProcessor = new TranslateControllerRouteProcessor(RouteTranslationConfiguration, LoggerFactory.CreateLogger <TranslateControllerRouteProcessor>()) { Culture = CurrentCultures.Single(), Template = template, }; RouteTranslationStore.Add(new RouteSelectorProcessorPair { Selector = CurrentRouteSelectorFunc(), Processor = routeProcessor, }); return(this); }
public RouteTranslationBuilder Filter <T>(Expression <Action <T> > expression) { string actionName = null; Type[] actionArguments = null; if (expression != null) { MethodCallExpression methodCall = expression.Body as MethodCallExpression; if (methodCall == null) { throw new ArgumentException("Expression must be a MethodCallExpression", nameof(expression)); } actionName = methodCall.Method.Name; actionArguments = methodCall.Arguments.Select(x => x.Type).ToArray(); } if (CurrentRouteSelectorFunc == null) { throw new InvalidOperationException( $"{typeof(FilterRouteSelector)} cannot be used before any RouteSelector is defined."); } Func <IRouteSelector> previousRouteSelectorFunc = CurrentRouteSelectorFunc; CurrentRouteSelectorFunc = (Func <FilterRouteSelector>)(() => { FilterRouteSelector filterRouteSelector = new FilterRouteSelector(previousRouteSelectorFunc()) { Controller = Regex.Replace(typeof(T).Name, "Controller$", string.Empty), ControllerNamespace = typeof(T).Namespace, Action = actionName, ActionArguments = actionArguments, Localizer = RouteTranslationConfiguration.Localizer, Cultures = CurrentCultures.ToArray(), }; if ((previousRouteSelectorFunc as Func <FilterRouteSelector>) != null) { FilterRouteSelector previousFilterRouteSelector = ((Func <FilterRouteSelector>)previousRouteSelectorFunc)(); filterRouteSelector.FilterControllerOrActionWhenNoTranslatedRouteLeft = previousFilterRouteSelector .FilterControllerOrActionWhenNoTranslatedRouteLeft; filterRouteSelector.FilterControllerOrActionWhenNoUntranslatedRouteLeft = previousFilterRouteSelector .FilterControllerOrActionWhenNoUntranslatedRouteLeft; } if ((previousRouteSelectorFunc as Func <TranslatedRoutesRouteSelector>) != null) { filterRouteSelector.FilterControllerOrActionWhenNoTranslatedRouteLeft = true; } if ((previousRouteSelectorFunc as Func <UntranslatedRoutesRouteSelector>) != null) { filterRouteSelector.FilterControllerOrActionWhenNoUntranslatedRouteLeft = true; } return(filterRouteSelector); }); return(this); }