By CodeJustin
via dotnetaddict.dotnetdevelopersjournal.com
Published: Jun 29 2009 / 09:22
T4 is a Text Template engine that comes with Visual Studio 2008. I'm a little fuzzy on its origins and true purpose, but from the documentation that is available on MSDN, it looks as though T4 was originally conceived as the underlying plumbing that allowed DSLs (Domain-Specific Languages) to programmatically generate compileable classes on the fly.
The benefit of this engine is that it's available for code generation even if you're not working on a DSL. In fact I would go so far as to say that regardless of it's original intent, T4 probably has wider appeal among developers looking to code generate as a solution to the "boilerplate of spaghetti" problem than it does among the relative minority of people building DSLs. I'm not saying that it's less meaningful to DSL builders, I'm just saying that there are more devs who need code generation for their day-to-day tasks than there are devs who are building DSLs.
Before diving into a sample I just want to try and make it clear that T4 is a code eneration utility. It handles those situations where you cannot fix your redundant or tedious code problems with inheritance, DI, or Aspects.



Comments
reboltutorial replied ago:
Interesting, I'm thinking about mixing it with my own DSL for generating C# code :
http://www.dzone.com/links/implement_a_c_code_generator_using_a_domain_speci.html
By the way DSL can be used on top of code generation for code generation.
Voters For This Link (7)
Voters Against This Link (0)