File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -908,6 +908,27 @@ public void TestCompileAndRun_IncludeDebuggingForTypedAnonymous_EnabledDebugging
908908 Assert . AreEqual ( "<h1>Hello Alex</h1>" , actual ) ;
909909 }
910910
911+ [ TestMethod ]
912+ public void TestCompileAndRun_ProjectEngineBuilderAction_IsInvoked ( )
913+ {
914+ var builderActionIsInvoked = false ;
915+ RazorEngine razorEngine = new RazorEngine ( ) ;
916+ IRazorEngineCompiledTemplate template = razorEngine . Compile ( "<h1>Hello @Model.Name</h1>" , builder =>
917+ {
918+ builder . IncludeDebuggingInfo ( ) ;
919+ builder . Options . ProjectEngineBuilderAction = ( x ) => builderActionIsInvoked = true ;
920+ } ) ;
921+
922+ template . EnableDebugging ( ) ;
923+
924+ string actual = template . Run ( new
925+ {
926+ Name = "Alex"
927+ } ) ;
928+
929+ Assert . IsTrue ( builderActionIsInvoked ) ;
930+ }
931+
911932 [ TestMethod ]
912933 public void TestCompileAndRun_Typed_EnabledDebuggingThrowsException ( )
913934 {
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
6767 ( builder ) =>
6868 {
6969 builder . SetNamespace ( options . TemplateNamespace ) ;
70+ options . ProjectEngineBuilderAction ? . Invoke ( builder ) ;
7071 } ) ;
7172
7273 RazorSourceDocument document = RazorSourceDocument . Create ( templateSource , fileName ) ;
Original file line number Diff line number Diff line change 33using System . Runtime . InteropServices ;
44using Microsoft . CodeAnalysis ;
55using System ;
6+ using Microsoft . AspNetCore . Razor . Language ;
67
78namespace RazorEngineCore
89{
@@ -22,6 +23,7 @@ public class RazorEngineCompilationOptions
2223 "System.Collections" ,
2324 "System.Collections.Generic"
2425 } ;
26+ public Action < RazorProjectEngineBuilder > ProjectEngineBuilderAction { get ; set ; }
2527
2628 public RazorEngineCompilationOptions ( )
2729 {
You can’t perform that action at this time.
0 commit comments