Generating C# from an UML model with T4
// April 7th, 2009 // 1 Comment » // .Net, T4, Tools, UML
It would take quite a few blog entries to cover all that goes into the heading of this post. So I won’t do that :-). I’ll try to be short.

Code Generation with T4
First some background though. I’m using a product called Enterprise Architect to do all my UML modeling. It is a decent product that is not too expensive. It has built in support for generating code in various languages, C# being one of them. Problem is the template language for the code generation sucks. Enter Visual Studio and T4! That would be T4 as in “Text Template Transformation Toolkit”, not the Terminator Salvation movie. Sorry to disappoint you there.
The short story is that T4 is a templating tool built right into Visual Studio! If you’re using VS 2008 you already have it installed. For more information and a great link resource, check out Scott Hanselman’s blog post about T4 (and also listen to his accompanying Hanselminutes podcast that covers the topic).
So basically I have created T4 templates that communicates with my UML model and generate all relevant classes and connections between them. Hopefully I will find the time to do a more complete writeup on these topics and also provide you with some code. Until then, all you need to know is that for me, T4 is a great tool!

