I have a template that generates a class and a complementary interface to go with it from a script like so:
<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension="cs" #>
<#@ include file="T4Toolbox.tt" #>
<#@ include file="../BusinessObjectTemplate.tt" #>
<#
BusinessObjectTemplate template = new BusinessObjectTemplate();
template.BusinessName="Priority";
template.PropertyList=new Dictionary<string,BusinessPropertyT4>{
{"Value",new BusinessPropertyT4("byte")},
{"Display",new BusinessPropertyT4("string")},
};
template.TopRegionText="internal ModelPriority(byte value, String display)\r\n\t\t{\r\n"+
"\t\t\tValue=value;\r\n"+"\t\t\tDisplay=display;\r\n"+ "\t\t}";
template.Render();
#>
How would I generate the TopRegionText(constructor) from the script without feeding it a direct string and have it go into the right place in the template?
Assuming that you would prefer to use templating functionality of T4 to generate the constructor, you can define a virtual method (i.e. GenerateTopRegionText) in BusinessObjectTemplate class and call it from BusinessObjectTemplate.TransformText method. Having done that, you can override it like so:
More here.