diff --git a/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs b/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs index e4f003e02..f8ca7ca1e 100644 --- a/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs +++ b/src/Microsoft.AspNet.Razor/CodeGenerators/CSharpLineMappingWriter.cs @@ -114,7 +114,8 @@ public void Dispose() { // Need to add an additional line at the end IF there wasn't one already written. // This is needed to work with the C# editor's handling of #line ... - var endsWithNewline = _writer.GenerateCode().EndsWith("\n"); + var builder = _writer.Builder; + var endsWithNewline = builder.Length > 0 && builder[builder.Length - 1] == '\n'; // Always write at least 1 empty line to potentially separate code from pragmas. _writer.WriteLine(); diff --git a/src/Microsoft.AspNet.Razor/CodeGenerators/CodeWriter.cs b/src/Microsoft.AspNet.Razor/CodeGenerators/CodeWriter.cs index 8190243d0..171883c22 100644 --- a/src/Microsoft.AspNet.Razor/CodeGenerators/CodeWriter.cs +++ b/src/Microsoft.AspNet.Razor/CodeGenerators/CodeWriter.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Text; namespace Microsoft.AspNet.Razor.CodeGenerators { @@ -18,6 +19,8 @@ public class CodeWriter : IDisposable private int _currentLineIndex; private int _currentLineCharacterIndex; + public StringBuilder Builder => _writer.GetStringBuilder(); + public string LastWrite { get; private set; } public int CurrentIndent { get; private set; }