Skip to content

Commit 3ddda23

Browse files
committed
- do not include GeneratedSourceCode and TemplateSource if IncludeDebuggingInfo not set to true
- cleanup
1 parent 93a6293 commit 3ddda23

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

RazorEngineCore/RazorEngine.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.CodeAnalysis.CSharp;
1111
using Microsoft.CodeAnalysis.Emit;
1212
using System.Reflection.Metadata;
13-
using System.Resources;
1413

1514
namespace RazorEngineCore
1615
{
@@ -47,13 +46,16 @@ public IRazorEngineCompiledTemplate Compile(string content, Action<IRazorEngineC
4746

4847
public Task<IRazorEngineCompiledTemplate> CompileAsync(string content, Action<IRazorEngineCompilationOptionsBuilder> builderAction = null, CancellationToken cancellationToken = default)
4948
{
50-
return Task.Factory.StartNew(() => this.Compile(content: content, builderAction: builderAction, cancellationToken: cancellationToken));
49+
return Task.Factory.StartNew(() => this.Compile(
50+
content,
51+
builderAction,
52+
cancellationToken));
5153
}
5254

5355
protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(string templateSource, RazorEngineCompilationOptions options, CancellationToken cancellationToken)
54-
5556
{
5657
templateSource = this.WriteDirectives(templateSource, options);
58+
5759
string projectPath = @".";
5860
string fileName = string.IsNullOrWhiteSpace(options.TemplateFilename)
5961
? Path.GetRandomFileName() + ".cshtml"
@@ -67,20 +69,17 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
6769
builder.SetNamespace(options.TemplateNamespace);
6870
});
6971

70-
7172
RazorSourceDocument document = RazorSourceDocument.Create(templateSource, fileName);
7273

7374
RazorCodeDocument codeDocument = engine.Process(
7475
document,
7576
null,
7677
new List<RazorSourceDocument>(),
7778
new List<TagHelperDescriptor>());
78-
7979

8080
RazorCSharpDocument razorCSharpDocument = codeDocument.GetCSharpDocument();
8181
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(razorCSharpDocument.GeneratedCode, cancellationToken: cancellationToken);
8282

83-
8483
CSharpCompilation compilation = CSharpCompilation.Create(
8584
fileName,
8685
new[]
@@ -114,7 +113,6 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
114113

115114
EmitResult emitResult = compilation.Emit(assemblyStream, pdbStream, cancellationToken: cancellationToken);
116115

117-
118116
if (!emitResult.Success)
119117
{
120118
RazorEngineCompilationException exception = new RazorEngineCompilationException()
@@ -130,12 +128,11 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
130128
{
131129
AssemblyByteCode = assemblyStream.ToArray(),
132130
PdbByteCode = pdbStream?.ToArray(),
133-
GeneratedSourceCode = razorCSharpDocument.GeneratedCode,
134-
TemplateSource = templateSource,
131+
GeneratedSourceCode = options.IncludeDebuggingInfo ? razorCSharpDocument.GeneratedCode : null,
132+
TemplateSource = options.IncludeDebuggingInfo ? templateSource : null,
135133
TemplateNamespace = options.TemplateNamespace,
136134
TemplateFileName = fileName
137135
};
138-
139136
}
140137

141138
protected virtual string WriteDirectives(string content, RazorEngineCompilationOptions options)
@@ -152,7 +149,5 @@ protected virtual string WriteDirectives(string content, RazorEngineCompilationO
152149

153150
return stringBuilder.ToString();
154151
}
155-
156-
157152
}
158-
}
153+
}

RazorEngineCore/RazorEngineCompiledTemplate.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4-
using System.Text;
54
using System.Threading.Tasks;
65

76
namespace RazorEngineCore

RazorEngineCore/RazorEngineCompiledTemplateMeta.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace RazorEngineCore
77
{
8-
98
public class RazorEngineCompiledTemplateMeta
109
{
1110
public byte[] AssemblyByteCode { get; set; }

RazorEngineCore/RazorEngineCompiledTemplateT.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,5 @@ public async Task<string> RunAsync(Action<T> initializer)
6565

6666
return await instance.ResultAsync();
6767
}
68-
69-
7068
}
7169
}

0 commit comments

Comments
 (0)