I must admit I kinda missed the boat with T4 templates and what was capable of them, which annoys me, so I set out to try and have a look at them the other day, but low and behold, Karl Shifflett has beaten me too it.
Karl has an excellent blog post http://karlshifflett.wordpress.com/2009/10/30/t4-preprocessed-text-templates-in-visual-studio-2010/ which talks about the new partial class support available for T4 templates in VS2010.
In case you have totally missed the boat, T4 templates are a text template that when saved will run some code. Now this code can do all sorts of things as demonstrated so beautifully by Daniel Vaughan in his excellent T4 EnvDTE article over at Code Project.
Daniel basically shows how to use T4 to create type safe metadata to get rid of magic strings (which we all hate).
Ok so getting back to T4 basics, T4 uses some classic ASP type syntax and you can embed C# code between special characters. Again, see Karl for an example of this.
One thing is for sure T4 looks to be getting a whole lot better in VS2010. can’t wait.
Oh and here are some other good T4 resources:
This article was originally posted at
http://sachabarber.net?p=578
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
Both of these at Sussex University UK.
Award(s)
I am lucky enough to have won a few awards for Zany Crazy code articles over the years
- Microsoft C# MVP 2016
- Codeproject MVP 2016
- Microsoft C# MVP 2015
- Codeproject MVP 2015
- Microsoft C# MVP 2014
- Codeproject MVP 2014
- Microsoft C# MVP 2013
- Codeproject MVP 2013
- Microsoft C# MVP 2012
- Codeproject MVP 2012
- Microsoft C# MVP 2011
- Codeproject MVP 2011
- Microsoft C# MVP 2010
- Codeproject MVP 2010
- Microsoft C# MVP 2009
- Codeproject MVP 2009
- Microsoft C# MVP 2008
- Codeproject MVP 2008
- And numerous codeproject awards which you can see over at my blog