예제 #1
0
        public static Route MapComplexRoute(this RouteCollection routes, string name, string url, object rules, object defaults, object constraints, string[] namespaces)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (rules == null)
            {
                throw new ArgumentNullException("rules");
            }

            var route = new MvcComplexRoute(url, new RouteValueDictionary(rules), new MvcRouteHandler())
            {
                Defaults    = new RouteValueDictionary(defaults),
                Constraints = new RouteValueDictionary(constraints),
                DataTokens  = new RouteValueDictionary()
            };

            if ((namespaces != null) && (namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = namespaces;
            }
            routes.Add(name, route);

            return(route);
        }
예제 #2
0
        private Route Create(string name, string url, FluentRouteConfiguration config)
        {
            var route = default(Route);

            var handler     = config.Handler ?? new MvcRouteHandler();
            var defaults    = config.Defaults == null ? new RouteValueDictionary() : new RouteValueDictionary(config.Defaults);
            var constraints = config.Constraints == null ? new RouteValueDictionary() : new RouteValueDictionary(config.Constraints);
            var dataTokens  = config.DataTokens == null ? new RouteValueDictionary() : new RouteValueDictionary(config.DataTokens);

            // create complex route only when required
            if (config.Rules != null && config.Rules.Any())
            {
                // no need to clone rules, it's always cloned from within MvcComplexRoute
                route = new MvcComplexRoute(url, config.Rules, handler);
            }
            else
            {
                route = new Route(url, handler);
            }

            route.Defaults    = defaults;
            route.Constraints = constraints;
            route.DataTokens  = dataTokens;

            if ((config.Namespaces != null) && (config.Namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = config.Namespaces;
            }

            if (m_areaName != null && m_areaName.Length > 0)
            {
                route.DataTokens["area"] = m_areaName;
                route.DataTokens["UseNamespaceFallback"] = config.Namespaces == null || config.Namespaces.Length == 0;
            }

            return(route);
        }
예제 #3
0
        public static Route MapComplexRoute(this RouteCollection routes, string name, string url, object rules, object defaults, object constraints, string[] namespaces)
        {
            if (routes == null)
                throw new ArgumentNullException("routes");
            if (url == null)
                throw new ArgumentNullException("url");
            if (rules == null)
                throw new ArgumentNullException("rules");

            var route = new MvcComplexRoute(url, new RouteValueDictionary(rules), new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(defaults),
                Constraints = new RouteValueDictionary(constraints),
                DataTokens = new RouteValueDictionary()
            };

            if ((namespaces != null) && (namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = namespaces;
            }
            routes.Add(name, route);

            return route;
        }
예제 #4
0
        private Route Create(string name, string url, FluentRouteConfiguration config)
        {
            var route = default(Route);

            var handler = config.Handler ?? new MvcRouteHandler();
            var defaults = config.Defaults == null ? new RouteValueDictionary() : new RouteValueDictionary(config.Defaults);
            var constraints = config.Constraints == null ? new RouteValueDictionary() : new RouteValueDictionary(config.Constraints);
            var dataTokens = config.DataTokens == null ? new RouteValueDictionary() : new RouteValueDictionary(config.DataTokens);

            // create complex route only when required
            if (config.Rules != null && config.Rules.Any())
                // no need to clone rules, it's always cloned from within MvcComplexRoute
                route = new MvcComplexRoute(url, config.Rules, handler);
            else
                route = new Route(url, handler);

            route.Defaults = defaults;
            route.Constraints = constraints;
            route.DataTokens = dataTokens;

            if ((config.Namespaces != null) && (config.Namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = config.Namespaces;
            }

            if (m_areaName != null && m_areaName.Length > 0)
            {
                route.DataTokens["area"] = m_areaName;
                route.DataTokens["UseNamespaceFallback"] = config.Namespaces == null || config.Namespaces.Length == 0;
            }

            return route;
        }