Esempio n. 1
0
        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}\"");
            }
        }
Esempio n. 2
0
        /// <include file="../../docs/Microsoft.Maui.Controls/Routing.xml" path="//Member[@MemberName='RegisterRoute'][1]/Docs" />
        public static void RegisterRoute(string route, RouteFactory factory)
        {
            if (!String.IsNullOrWhiteSpace(route))
            {
                route = FormatRoute(route);
            }
            ValidateRoute(route, factory);

            s_routes[route] = factory;
        }