My Writings. My Thoughts.

Generating C# from an UML model with T4

// April 7th, 2009 // .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

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!

5 Total TweetBacks: (Tweet this post)
  • en: Looking for the score of Smile by Charles Cheplin for piano or keyboard 07/11/09 12:26pm
  • en: @davidrand I'm curious...did you watch the video the pic was a capture from, or just look at the picture? It's a world of difference. 07/11/09 12:26pm
  • en: Downloading Daggerfall. One of these days, I'll play a game that's come out in the past year or so. 07/11/09 12:25pm
  • en: @anidoll Truthfulness.. or truthy-kinda-sorta-ish-ness? 07/11/09 12:25pm
  • en: @FeelthyFiles damn where u @ where they have a smokin room? Or did u nmake that up on ur own RICH!!! Lol 07/11/09 12:25pm

One Response to “Generating C# from an UML model with T4”

  1. Tim says:

    Great post. T4 Editor & UML Tools from tangible includes a similar template that transfers code from Sparx to DSL Tools.

    You can download it from t4editor.tangible-engineering.com
    Then right click the T4 Editor pane and select Insert Code From Gallery -> Search Online Tempaltes to get the latest tempalates.

    Indeed everyone can publish his templates in the build-in online gallery.

    Check it out.

Leave a Reply