private static IRouteHandler GetInstanceOfRouteHandler(RouteElement route) { IRouteHandler routeHandler; if (string.IsNullOrEmpty(route.RouteHandlerType)) { return(new MvcRouteHandler()); } try { Type routeHandlerType = Type.GetType(route.RouteHandlerType); routeHandler = Activator.CreateInstance(routeHandlerType) as IRouteHandler; } catch (Exception ex) { throw new ApplicationException( string.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType), ex); } return(routeHandler); }
/// <summary> /// Registers the routes in the web.config file. /// </summary> /// <param name="routes">The <see cref="RouteCollection"/> to add routes to.</param> /// <param name="forceLowercase">Forces the routes to be lower case.</param> public static void RegisterRoutes(RouteCollection routes, bool forceLowercase) { RouteTableSection routesTableSection = GetRouteTableConfigurationSection(); if (routesTableSection == null || routesTableSection.Routes.Count < 1) { return; } for (int i = 0; i < routesTableSection.Routes.Count; i++) { RouteElement routeElement = routesTableSection.Routes[i]; Route route; if (forceLowercase) { route = new LowercaseRoute( routeElement.Url, GetDefaults(routeElement), GetConstraints(routeElement), GetDataTokens(routeElement), GetInstanceOfRouteHandler(routeElement)); } else { route = new Route( routeElement.Url, GetDefaults(routeElement), GetConstraints(routeElement), GetDataTokens(routeElement), GetInstanceOfRouteHandler(routeElement)); } routes.Add(routeElement.Name, route); } }
private static RouteValueDictionary GetDefaults(RouteElement route) { return(GetDictionary(route.Defaults.Attributes)); }
private static RouteValueDictionary GetDataTokens(RouteElement route) { return(GetDictionary(route.DataTokens.Attributes)); }
/// <summary> /// Adds the specified route. /// </summary> /// <param name="route">The route.</param> public void Add(RouteElement route) { BaseAdd(route); }
private static RouteValueDictionary GetConstraints(RouteElement route) { return(GetDictionary(route.Constraints.Attributes)); }
private static IRouteHandler GetInstanceOfRouteHandler(RouteElement route) { IRouteHandler routeHandler; if (string.IsNullOrEmpty(route.RouteHandlerType)) return new MvcRouteHandler(); try { Type routeHandlerType = Type.GetType(route.RouteHandlerType); routeHandler = Activator.CreateInstance(routeHandlerType) as IRouteHandler; } catch (Exception ex) { throw new ApplicationException( string.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType), ex); } return routeHandler; }
private static RouteValueDictionary GetDataTokens(RouteElement route) { return GetDictionary(route.DataTokens.Attributes); }
private static RouteValueDictionary GetDefaults(RouteElement route) { return GetDictionary(route.Defaults.Attributes); }
private static RouteValueDictionary GetConstraints(RouteElement route) { return GetDictionary(route.Constraints.Attributes); }