Would be possible to add options into template header?

Jul 9, 2012 at 2:09 PM

Overall razorgenerator is very nice project, but there are two things, that I don't like much in razorgenerator templates generated code:

1) it adds too much whitespace. Let's say I have following template:

@* Generator: Template *@
@using System.Linq

@functions {
    public string Message { get; set; }

@foreach(var i in Enumerable.Range(1, 50))
    Hello @Message @i!

it generates code like:

  public override void Execute()




            #line 8 "..\..\SampleTemplate.cshtml"
 foreach(var i in Enumerable.Range(1, 50))

            #line default
            #line hidden
WriteLiteral("    ");

So, 4 blank lines, before outputing actual text, I would prefer to have an option that would allow to skip whitespace from template, that does not affect output. It may require some more processing effort generating code, but now I need processing effort after each template transform to remove whitespace, that kills performance.

2) if there's long html in template, it is concatenated using +, that is also not very friendly for performance - if it is for better readability, could we make it optional?

Jul 30, 2012 at 1:00 PM

Note that RazorGenerator just uses the standard Razor engine to generate code, so the behavior you describe is not related to RazorGenerator.

But I don't think concatenating literal strings with + should have any perf effect. I expect the compiler to generate the exact same code.

Jul 30, 2012 at 1:34 PM

I've just checked regarding concatenating literal strings and Razor generates the same code, but I didn't had in count, that literals are constant, not dynamic, so compiler turns that into effective code, so you're right.

But regarding whitespace, I think it is possible to use some kind of code transform to get rid of those, like it is done with RemoveLineHiddenPragmas class.

Jul 30, 2012 at 3:29 PM

@dziedrius I'm going to finally spend some time this week to see if I can take advantage of a minification tool (http://razorgenerator.codeplex.com/discussions/360929) in our generator. 

Jul 30, 2012 at 3:38 PM

Ideally, we don't want to do anything different in RazorGenerator from what you'd do in a standard Razor page.