From 458e6d1832724a26eed7b330b40e2b48d9131a47 Mon Sep 17 00:00:00 2001 From: Alexander Selishchev Date: Fri, 17 Nov 2023 18:11:39 +0300 Subject: [PATCH] example app update with debugging example --- ExampleAppNET5/ExampleAppNET5.csproj | 9 ++++ ExampleAppNET5/Program.cs | 63 ++++++++++++++-------------- ExampleAppNET5/template1.cshtml | 24 +++++++++++ ExampleAppNET5/template2.cshtml | 24 +++++++++++ 4 files changed, 89 insertions(+), 31 deletions(-) create mode 100644 ExampleAppNET5/template1.cshtml create mode 100644 ExampleAppNET5/template2.cshtml diff --git a/ExampleAppNET5/ExampleAppNET5.csproj b/ExampleAppNET5/ExampleAppNET5.csproj index d2eb4f8..4172dcb 100644 --- a/ExampleAppNET5/ExampleAppNET5.csproj +++ b/ExampleAppNET5/ExampleAppNET5.csproj @@ -9,4 +9,13 @@ + + + Always + + + Always + + + diff --git a/ExampleAppNET5/Program.cs b/ExampleAppNET5/Program.cs index 3fde7ed..4d7ae7c 100644 --- a/ExampleAppNET5/Program.cs +++ b/ExampleAppNET5/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Reflection; using System.Runtime.InteropServices; using RazorEngineCore; @@ -9,45 +10,45 @@ namespace ExampleAppNET5 class Program { - static string Content = @" -Hello @Model.Name - -@foreach(var item in @Model.Items) -{ -
- @item
-} + static void Main(string[] args) + { + IRazorEngine razorEngine = new RazorEngine(); + IRazorEngineCompiledTemplate template1 = razorEngine.Compile("Hello

@Model.Name

"); -
+ string result = template1.Run(new + { + Name = "Alex" + }); - - @{ RecursionTest(3); } - + Console.WriteLine(result); + } -@{ - void RecursionTest(int level){ - if (level <= 0) - { - return; - } - -
LEVEL: @level
- @{ RecursionTest(level - 1); } - } -}"; - static void Main(string[] args) + static void ReadFromFileAndRun() { IRazorEngine razorEngine = new RazorEngine(); - IRazorEngineCompiledTemplate template = razorEngine.Compile(Content); + string templateText = File.ReadAllText("template2.cshtml"); + + IRazorEngineCompiledTemplate template2 = razorEngine.Compile(templateText, builder => + { + builder.IncludeDebuggingInfo(); + }); + + if (!Directory.Exists("Temp")) + { + Directory.CreateDirectory("Temp"); + } + + template2.EnableDebugging("Temp"); - string result = template.Run(new + string result = template2.Run(new { - Name = "Alexander", - Items = new List() - { - "item 1", - "item 2" - } + Name = "Alexander", + Items = new List() + { + "item 1", + "item 2" + } }); Console.WriteLine(result); diff --git a/ExampleAppNET5/template1.cshtml b/ExampleAppNET5/template1.cshtml new file mode 100644 index 0000000..eb7654e --- /dev/null +++ b/ExampleAppNET5/template1.cshtml @@ -0,0 +1,24 @@ +Hello @Model.Name + +@foreach(var item in @Model.Items) +{ +
- @item
+} + +
+ + + @{ RecursionTest(3); } + + +@{ + void RecursionTest(int level){ + if (level <= 0) + { + return; + } + +
LEVEL: @level
+ @{ RecursionTest(level - 1); } + } +} \ No newline at end of file diff --git a/ExampleAppNET5/template2.cshtml b/ExampleAppNET5/template2.cshtml new file mode 100644 index 0000000..9b0c898 --- /dev/null +++ b/ExampleAppNET5/template2.cshtml @@ -0,0 +1,24 @@ +
+

Hello

+ + @{ Breakpoint(); } + + @if (Model != null) + { +

Hello @Model

+ } + +

111

+ + @if (Model != null) + { +

Hello @Model

+ } + +

111

+ + @if (Model != null) + { +

Hello @Model

+ } +
\ No newline at end of file