Reputation: 2076
T4 has existed for several years in Visual Studio, but doesn't get a lot of attention. However, for those that know it, there seems to be some very creative and useful purposes.
I am researching some different ways that T4 is used, and I would appreciate to hear how YOU may have used it for real life scenarios. I am primarily interested in non-standard and creative uses.
Some interesting examples:
Note: I realize this is a discussion-oriented question, but the answers could be helpful to others. I have tagged it as subjective and also marked as "community wiki", so please allow the question to remain open. Thanks!
Upvotes: 28
Views: 3315
Reputation: 115773
I've used the T4 Templates within the sharp-architecture to generate everything from models to controllers to basic views.
Definitely worth checking out, even if you just want to see some advanced examples of T4 templates in action
Upvotes: 4
Reputation: 2720
I've used T4 to generate:
Upvotes: 2
Reputation: 2775
I use T4 to:
It gives me a good, quick, simple, basic starting point for my projects.
And the best is I'm in control.
Here you can download an example of my templates
Upvotes: 4
Reputation: 18325
I am not a big fan of the stringy-ness of app.config/web.config, so I use T4 to read those files and make an AppSettings/WebSettings class that wraps the connection strings and key/values in a real class. This means that, as long as I always use AppSettings.SomeValue to reference my app.config, I get compile time checking, which is really nice.
Upvotes: 8
Reputation: 1
See here for a list of more than 30 T4 Generators from the community in several areas including ASP.NET,WCF, UML, ADO.NET, .NET
http://t4-editor.tangible-engineering.com/How-Do-I-With-T4-Editor-Text-Templates.htm
Upvotes: 1
Reputation: 161773
T4 Templates are used heavily in the Web Service Software Factory (Service Factory).
Upvotes: 1
Reputation: 53
Check out this podcast on T4 by Scott Hanselman talking with Kathleen Dollard.
http://www.hanselminutes.com/default.aspx?showID=170
Upvotes: 2
Reputation: 180787
LINQ to SQL templates for T4
http://l2st4.codeplex.com/
Templates replicating the functionality of the SQLMetal and the LINQ to SQL classes designer code-generators for both C# and VB.Net requiring just Visual Studio 2008.
Upvotes: 2
Reputation: 116977
SubSonic 3.0 makes heavy use of T4 templates for generating your entity code.
Essentially it calls GetSchema()
on your database connection and runs each table it finds through the T4 entity template. The great thing about using T4 here is that if you don't like the way it's handling your database schema, just edit the template.
I've tweaked the T4's to handle MySQL databases better for my situation, as I make use of many tinyint
columns which the default T4 maps to byte
types. A quick edit to the T4 gave me the type I wanted instead for my application entities.
Upvotes: 2