Skip to content

Commit 458e6d1

Browse files
committed
example app update with debugging example
1 parent caf4ce1 commit 458e6d1

File tree

4 files changed

+89
-31
lines changed

4 files changed

+89
-31
lines changed

ExampleAppNET5/ExampleAppNET5.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@
99
<ProjectReference Include="..\RazorEngineCore\RazorEngineCore.csproj" />
1010
</ItemGroup>
1111

12+
<ItemGroup>
13+
<None Update="template1.cshtml">
14+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
15+
</None>
16+
<None Update="template2.cshtml">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
1221
</Project>

ExampleAppNET5/Program.cs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Reflection;
45
using System.Runtime.InteropServices;
56
using RazorEngineCore;
@@ -9,45 +10,45 @@ namespace ExampleAppNET5
910

1011
class Program
1112
{
12-
static string Content = @"
13-
Hello @Model.Name
14-
15-
@foreach(var item in @Model.Items)
16-
{
17-
<div>- @item</div>
18-
}
13+
static void Main(string[] args)
14+
{
15+
IRazorEngine razorEngine = new RazorEngine();
16+
IRazorEngineCompiledTemplate template1 = razorEngine.Compile("Hello <h1>@Model.Name</h1>");
1917

20-
<div data-name=""@Model.Name""></div>
18+
string result = template1.Run(new
19+
{
20+
Name = "<b>Alex</b>"
21+
});
2122

22-
<area>
23-
@{ RecursionTest(3); }
24-
</area>
23+
Console.WriteLine(result);
24+
}
2525

26-
@{
27-
void RecursionTest(int level){
28-
if (level <= 0)
29-
{
30-
return;
31-
}
32-
33-
<div>LEVEL: @level</div>
34-
@{ RecursionTest(level - 1); }
35-
}
36-
}";
3726

38-
static void Main(string[] args)
27+
static void ReadFromFileAndRun()
3928
{
4029
IRazorEngine razorEngine = new RazorEngine();
41-
IRazorEngineCompiledTemplate template = razorEngine.Compile(Content);
30+
string templateText = File.ReadAllText("template2.cshtml");
31+
32+
IRazorEngineCompiledTemplate template2 = razorEngine.Compile(templateText, builder =>
33+
{
34+
builder.IncludeDebuggingInfo();
35+
});
36+
37+
if (!Directory.Exists("Temp"))
38+
{
39+
Directory.CreateDirectory("Temp");
40+
}
41+
42+
template2.EnableDebugging("Temp");
4243

43-
string result = template.Run(new
44+
string result = template2.Run(new
4445
{
45-
Name = "Alexander",
46-
Items = new List<string>()
47-
{
48-
"item 1",
49-
"item 2"
50-
}
46+
Name = "Alexander",
47+
Items = new List<string>()
48+
{
49+
"item 1",
50+
"item 2"
51+
}
5152
});
5253

5354
Console.WriteLine(result);

ExampleAppNET5/template1.cshtml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Hello @Model.Name
2+
3+
@foreach(var item in @Model.Items)
4+
{
5+
<div>- @item</div>
6+
}
7+
8+
<div data-name=""@Model.Name""></div>
9+
10+
<area>
11+
@{ RecursionTest(3); }
12+
</area>
13+
14+
@{
15+
void RecursionTest(int level){
16+
if (level <= 0)
17+
{
18+
return;
19+
}
20+
21+
<div>LEVEL: @level</div>
22+
@{ RecursionTest(level - 1); }
23+
}
24+
}

ExampleAppNET5/template2.cshtml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div>
2+
<h1>Hello</h1>
3+
4+
@{ Breakpoint(); }
5+
6+
@if (Model != null)
7+
{
8+
<h2>Hello @Model</h2>
9+
}
10+
11+
<h3>111</h3>
12+
13+
@if (Model != null)
14+
{
15+
<h2>Hello @Model</h2>
16+
}
17+
18+
<h3>111</h3>
19+
20+
@if (Model != null)
21+
{
22+
<h2>Hello @Model</h2>
23+
}
24+
</div>

0 commit comments

Comments
 (0)