Windows Forms and Generating Code

Mar 2, 2013 at 5:30 PM
I'm kind of struggling in an attempt to create a dynamic code generator using T4
  1. I have a windows app that reads mutilple files.
  2. For each file read, I need to collection of code snippets, in a java file.
I used Tangible t4 Editor and created a new tt file like this:
<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".java" #>
<#@ Assembly Name="System.Core" #>
<#@ Assembly Name="System.Windows.Forms" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 
<#
   // insert your template code here the tempalte code will be syntaxhighlighted 
   // and you will have intellisense for all namespaces in the full edition
   string Greeting = "Hello";
#>
// This is the output code from your template
// you only get syntax-highlighting here - not intellisense
namespace JAVA_UTILITY{
  class MyGeneratedClass{
     static void main (string[] args){
       System.Console.WriteLine("<#= Greeting #>, the time is now: <#=System.DateTime.Now.ToString() #>");
}

     
     
  }

<#+
  // Insert any template procedures here
  void foo(){}
#>
The problem I am having a hard time wrapping my head around is,
  1. How this tt.file gets called at run time
  2. How do I access and set say a collection of properties within this .tt file?
Thanks in advance for any help.

Doug
Coordinator
Mar 4, 2013 at 2:07 AM