Saturday, 15 August 2015

c# - Process multiple T4 templates with custom tool -



c# - Process multiple T4 templates with custom tool -

i've got dsl model , multiple t4 templates generate code corresponding model. want templates executed upon save of model. each template creates multiple output files. know theoretically how create custom tool model process template , homecoming generated code. how can process multiple templates, since ivssinglefilegenerator interface returns single generated file.

one way think create "master" t4 uses public methods templates shall processed. i've write ugly methods in each template hundreds of "write()" calls because within of "<#+" it's not possible write plain text in rest of template. or create 1 huge template contains code files generated. that's ugly , confusing think.

or there way somehow instantiate t4 template , allow process , create files on it's own? know how instantiate template can processed generated code i've handle self.

i didn't know how generate text class feature (<#+) it's described in msdn:

generate text class feature

<#+ private void createaccessor(modelclass classtype, modelclass associatedclass, string fromrolename, string torolename) { if(!string.isnullorempty(torolename) && !string.isnullorempty(fromrolename)) { string validclassname = makevalidname(associatedclass.name); string validfromname = makevalidname(fromrolename); string validtoname = makevalidname(torolename); #> private <#= validclassname#> <#= validfromname#>value; public <#= validclassname#> <#= validfromname#> { get{ homecoming <#= validfromname #>value; } set { if (<#= validfromname#> != value) { if (<#= validfromname#> != null) <#= validfromname#>.<#=validtoname#> = null; <#= validfromname#>value = value; if (value != null) { <#= validfromname#>value.<#=validtoname#>=this; } } } } <#+ } else { warning(string.format("ignoring bidirectionalassociation {0} {1} because sourcerolename or targetrolename not defined", classtype.name, associatedclass.name)); } } #>

c# visual-studio code-generation t4 texttemplate

No comments:

Post a Comment