/// <summary> /// Tries to resolve route parameters and map them to specific part of the url. /// </summary> /// <remarks> /// If needed tries to interpret the route value through <see cref="Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Routing.IRouteParamResolver"/> /// </remarks> /// <param name="actionMethod">The action method.</param> /// <param name="routeParam">The route parameter.</param> /// <param name="urlParam">The URL parameter.</param> /// <param name="parameterInfos">The parameter info.</param> /// <returns></returns> protected bool TryResolveRouteParam(MethodInfo actionMethod, string routeParam, string urlParam, IList <UrlSegmentInfo> parameterInfos) { if (routeParam.IsNullOrEmpty()) { return(false); } var parts = routeParam.Split(':'); var paramName = parts[0]; object paramValue = urlParam; if (parts.Length >= 2) { var actionParam = actionMethod.GetParameters().FirstOrDefault(p => p.Name == paramName); if (actionParam != null) { var routeConstraints = parts[1] .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(r => r.Trim()); IRouteParamResolver first = null; IRouteParamResolver last = null; foreach (var resolverName in routeConstraints) { var resolver = ObjectFactory.Resolve <IRouteParamResolver>(resolverName); if (resolver != null) { if (last != null) { last = last.SetNext(resolver); } else { first = last = resolver; } } } if (first == null || first.TryResolveParam(urlParam, out paramValue) == false) { return(false); } } } var paramInfo = new UrlSegmentInfo(); paramInfo.ParameterName = paramName; if (parts.Length >= 2) { paramInfo.ResolverName = parts[1]; } paramInfo.ParameterValue = paramValue; parameterInfos.Add(paramInfo); return(true); }
/// <inheritdoc /> public IRouteParamResolver SetNext(IRouteParamResolver nextResolver) { this.next = nextResolver; return this.Next; }
/// <inheritdoc /> public IRouteParamResolver SetNext(IRouteParamResolver nextResolver) { this.next = nextResolver; return(this.Next); }