public string Explode() { var treeContants = this.tree.Parameters.Cast<ConstantRouteExpressionParameter>().Select(y => y.Value).ToArray(); IEnumerable<RouteInfo> routeDatum = this.RenderingControllersRouteData; routeDatum = routeDatum.Where( x => ExpressiveRouteMatcher.IsMatch(this.host, x.Host, StringComparison.OrdinalIgnoreCase)); // ReSharper disable once ReplaceWithSingleCallToFirstOrDefault var routeData = routeDatum .Where(x => x.Type == typeof(T)) .Where(x => x.ExpressionTree.MethodName == this.tree.MethodName) .Where(x => ExpressiveRouteMatcher.IsMatch(x.ExpressionTree.Parameters, treeContants)) .FirstOrDefault(); if (routeData == null) { return null; } var pathMatcher = routeData.PathMatcher; if (pathMatcher != null) { var reverseRoutingObject = new Dictionary<string, object>(); foreach (var inputParameter in routeData.ExpressionTree.InputParameters) { var inputParamName = inputParameter.Name; int i = 0; foreach (var parameter in routeData.ExpressionTree.Parameters) { var funcParm = parameter as FunctionalRouteExpressionParameter; if (funcParm != null) { if (funcParm.Name == inputParamName) { break; } } i++; } reverseRoutingObject[inputParamName] = treeContants[i]; } return new Route(routeData.Path.Inject(reverseRoutingObject)).Explode(); //throw new InvalidOperationException("If you are routing to a complex Route (using regex), you must use the other API. (FindNamedDynamicRouteWith)"); } return new Route(routeData.Path).Explode(); }
protected IEnumerable <ExpressiveRouteData <T> > FilterByParts <T>( LinkedList <RouteInfo> routeDatum, string requestHost, string requestPath, HttpMethod requestMethod) { foreach (var routeData in routeDatum) { if (!ExpressiveRouteMatcher.IsMatch(requestHost, routeData.Host, StringComparison.OrdinalIgnoreCase)) { continue; } if (routeData.PathMatcher == null) { if (!ExpressiveRouteMatcher.IsMatch(requestPath, routeData.Path, StringComparison.Ordinal)) { continue; } } if (routeData.PathMatcher != null) { if (!ExpressiveRouteMatcher.IsMatchRegex(requestPath, routeData.PathMatcher)) { continue; } } if (!ExpressiveRouteMatcher.IsMatch(requestMethod, routeData.Method)) { continue; } yield return(new ExpressiveRouteData <T>(routeData.Type.GetClass().As <T>(), routeData.WrapperExpression)); } }