33// See the LICENSE file in the project root for more information.
44// Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 55
6+ using Microsoft . AspNetCore . Components . Rendering ;
67using Microsoft . AspNetCore . StaticFiles ;
78using Microsoft . Net . Http . Headers ;
9+ #if NET9_0_OR_GREATER
10+ using System . Reflection ;
11+ #endif
812
913namespace BootstrapBlazor . Server . Extensions ;
1014
@@ -19,6 +23,44 @@ public static bool IsSupportAssets(this IWebHostEnvironment webHost)
1923#endif
2024 }
2125
26+ /// <summary>
27+ ///
28+ /// </summary>
29+ /// <returns></returns>
30+ public static RenderFragment RenderAssets ( this ComponentBase component ) => builder =>
31+ {
32+ #if NET9_0_OR_GREATER
33+ var pi = component . GetType ( ) . GetProperty ( "Assets" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
34+ if ( pi != null )
35+ {
36+ var v = pi . GetValue ( component ) ;
37+ if ( v is ResourceAssetCollection assets )
38+ {
39+ builder . RenderCss ( $ "{ assets [ "_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css" ] } ") ;
40+ builder . RenderCss ( $ "{ assets [ "_content/BootstrapBlazor.MaterialDesign/css/md.min.css" ] } ") ;
41+ builder . RenderCss ( $ "{ assets [ "_content/BootstrapBlazor.BootstrapIcon/css/bootstrap.min.css" ] } ") ;
42+ builder . RenderCss ( $ "{ assets [ "_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css" ] } ") ;
43+ builder . RenderCss ( $ "{ assets [ "_content/BootstrapBlazor/css/motronic.min.css" ] } ") ;
44+ builder . RenderCss ( $ "{ assets [ "BootstrapBlazor.Server.styles.css" ] } ") ;
45+ builder . RenderCss ( $ "{ assets [ "css/site.css" ] } ") ;
46+
47+ builder . OpenComponent < ImportMap > ( 0 ) ;
48+ builder . CloseComponent ( ) ;
49+ }
50+ }
51+ #endif
52+ } ;
53+
54+ private static void RenderCss ( this RenderTreeBuilder builder , string url )
55+ {
56+ #if NET9_0_OR_GREATER
57+ builder . OpenElement ( 0 , "link" ) ;
58+ builder . AddAttribute ( 1 , "rel" , "stylesheet" ) ;
59+ builder . AddAttribute ( 2 , "href" , url ) ;
60+ builder . CloseElement ( ) ;
61+ #endif
62+ }
63+
2264 public static void ProcessCache ( this StaticFileResponseContext context , IConfiguration configuration )
2365 {
2466 if ( context . CanCache ( configuration , out var age ) )
0 commit comments