static void ValidateRoute(string route, RouteFactory routeFactory)
        {
            if (string.IsNullOrWhiteSpace(route))
            {
                throw new ArgumentNullException(nameof(route), "Route cannot be an empty string");
            }

            routeFactory = routeFactory ?? throw new ArgumentNullException(nameof(routeFactory), "Route Factory cannot be null");

            var uri = new Uri(route, UriKind.RelativeOrAbsolute);

            var parts = uri.OriginalString.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var part in parts)
            {
                if (IsImplicit(part))
                {
                    throw new ArgumentException($"Route contains invalid characters in \"{part}\"");
                }
            }

            RouteFactory existingRegistration = null;

            if (s_routes.TryGetValue(route, out existingRegistration) && !existingRegistration.Equals(routeFactory))
            {
                throw new ArgumentException($"Duplicated Route: \"{route}\"");
            }
        }
Exemplo n.º 2
0
        public static void RegisterRoute(string route, RouteFactory factory)
        {
            if (!ValidateRoute(route))
            {
                throw new ArgumentException("Route must contain only lowercase letters");
            }

            s_routes[route] = factory;
        }
Exemplo n.º 3
0
        public static void RegisterRoute(string route, RouteFactory factory)
        {
            if (!String.IsNullOrWhiteSpace(route))
            {
                route = FormatRoute(route);
            }
            ValidateRoute(route);

            s_routes[route] = factory;
        }