|
8 | 8 | namespace BootstrapBlazor.Components; |
9 | 9 |
|
10 | 10 | [ExcludeFromCodeCoverage] |
11 | | -#if NET5_0 |
12 | | -internal static class RouteTableFactory |
13 | | -{ |
14 | | - [NotNull] |
15 | | - private static Microsoft.AspNetCore.Components.Routing.IRouteTable? Routes { get; set; } |
16 | | - private static readonly HashSet<Assembly> _assemblies = new(); |
17 | | - |
18 | | - /// <summary> |
19 | | - /// |
20 | | - /// </summary> |
21 | | - /// <param name="assemblies"></param> |
22 | | - /// <param name="url"></param> |
23 | | - /// <returns></returns> |
24 | | - public static RouteContext Create(IEnumerable<Assembly>? assemblies, string url) |
25 | | - { |
26 | | - RefreshRouteTable(assemblies); |
27 | | - if (url.IndexOf("?") > 0) url = url[..url.IndexOf("?")]; |
28 | | - var routeContext = new Microsoft.AspNetCore.Components.Routing.RouteContext(url); |
29 | | - Routes.Route(routeContext); |
30 | | - return new RouteContext() |
31 | | - { |
32 | | - Handler = routeContext.Handler, |
33 | | - Parameters = routeContext.Parameters, |
34 | | - Segments = routeContext.Segments |
35 | | - }; |
36 | | - } |
37 | | - |
38 | | - private static void RefreshRouteTable(IEnumerable<Assembly>? assemblies) |
39 | | - { |
40 | | - assemblies ??= Enumerable.Empty<Assembly>(); |
41 | | - var assembliesSet = new HashSet<Assembly>(assemblies); |
42 | | - if (!_assemblies.SetEquals(assembliesSet)) |
43 | | - { |
44 | | - Routes = Microsoft.AspNetCore.Components.Routing.RouteTableFactory.Create(assemblies); |
45 | | - _assemblies.Clear(); |
46 | | - _assemblies.UnionWith(assembliesSet); |
47 | | - } |
48 | | - } |
49 | | -} |
50 | | -#else |
51 | 11 | internal static class RouteTableFactory |
52 | 12 | { |
53 | 13 | [NotNull] |
@@ -85,4 +45,3 @@ private static void RefreshRouteTable(IEnumerable<Assembly> assemblies) |
85 | 45 | } |
86 | 46 | } |
87 | 47 | } |
88 | | -#endif |
0 commit comments