Reputation: 41823
I have begun using T4 Templates for a few DAL enhancements.
However, I find they quickly get unwieldy and often produce poorly formatted code.
I am wondering if anyone has any good tips on organising these templates, and on getting great formatted code at the end.
So far my experience is:
#>
Upvotes: 2
Views: 1313
Reputation: 149
Use a third party formatting tool to Format your code after generation like Teleriks Just Code
Upvotes: 1
Reputation: 6606
Split your templates into control/data preparation logic and 'views' that do the output rendering.
Set up the data you need first and then write the output with the most minimal logic possible.
If you can parcel up the output into reusable chunks, then you can put those in method wrappers in <#+ #> blocks and do the structural work as a set of method calls.
Upvotes: 2
Reputation: 104999
T4 templates will format code as defined in the template. Indents are as defined in the file itself. To have great indented end result, T4 templates will often look strange and odd indented. But code is coloured so template's code is usually just fine.
I usually have a solution folder with all reusable T4 templates (if lots of them they can be put in subfolders as well). I give them the ttinclude
file extension. Others just include these and are put in place where needed.
Upvotes: 1