Mixing class feature and statement blocks

Apr 20, 2010 at 4:41 AM

I'm a T4 newbie trying to use T4 Toolbox to generate F# code based on some code that Oleg posted on stackoverflow.com, but it seems that class feature blocks can't be mixed with statement blocks. Here's my code:

 

<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension="txt" #>
<#@ include file="T4Toolbox.tt" #>
<#
    FSharpTemplate template = new FSharpTemplate();
    template.Output.Project = @"..\Library1\Library1.fsproj";
    template.Output.File = "Module2.fs";
    template.Render();
#>
<#+
class FSharpTemplate: Template
{
    public override string TransformText()
    {
#>

module Module2

<# for (int i = 0; i < 10; i++) { #>
<#= i #>
<# } #>

<#+
        return this.GenerationEnvironment.ToString();
    }
}

#>

 

 

And I get this error:

A Statement cannot appear after the first class feature in the template. Only boilerplate, expressions and other class features are allowed after the first class feature block.

So... how can I rewrite the template to achieve this?

BTW I posted this on stackoverflow.com a couple of days ago, sorry for the cross post but I didn't get any satisfactory answers... http://stackoverflow.com/questions/2660087/t4-toolbox-mixing-class-feature-and-statement-blocks

Thanks
Mauricio 

 

Coordinator
Apr 20, 2010 at 11:49 AM

Change the for and } blocks to be class feature blocks.

Oct 28, 2011 at 3:37 AM

We have good reasons to believe that if you try

<#+ for (int i = 0; i < 10; i++) { #>

<#= i #>

<#+ } #>

instead of

<# for (int i = 0; i < 10; i++) { #>

<#= i #>

<# } #>

your code will work...


We have tried to test your code but we were not able. Well we loaded the T4Toolbox from the web but were not sure of how to include the T4Toolbox.tt. Any idea?

Thank you.

The Yahawana Team.

Twitter: @yahawana