Question

Do you have any experience with T4 and T4 Editor? Can you compare it to CodeSmith or MyGeneration?

What code generators do you use? What do you recommend?

I want to use it for generatig of SPs. Is there anything else you find code generation useful?

Was it helpful?

Solution

What exactly you are trying to do? I guess it also depends on from where you are trying to generate the code (the model).

The advantage with Codesmith and MyGeneration is, they provide multiple options for you to generate your code - for eg, in MyGeneration, you can write your templates in various langs.

MyGeneration can provide a meta model of any DB and a lot of built in generator scripts - so that if you want to generate SPs, the easiest thing will be to use generators for MyGeneration - you can find generators for CRUD SPs right there. It also provides a reasonably good editor if you want to modify the generators.

If you are building a DSL or something (I mean, the model is coming from some where else), then you might consider using T4. How ever, T4 editing is not the easiest thing I've done, because there is no T4 editing support with in Visual Studio. You might consider purchasing Clarius T4 editor for good editing support.

OTHER TIPS

As a code generation engine, T4 is as capable as CodeSmith or MyGeneration. It's main advantage is the tight integration in Visual Studio; the main drawback is the smaller number of ready-to-use templates.

I personally prefer the T4 editor from Tangible because it works with the T4 Toolbox.

Oleg

Something that increases your productivity is by using the inbuilt snippets of Visual Studio.

tab tab

Like typing if and pressing tab twice will generate an if statement for you, and then basically you just fill in the blanks

try and two tabs will generate a try-catch block

etc...

There is a whole list of snippets which you can make use of.

Besides nowadays recommended T4 templates, there is another way to generate code in VS - MVC Scaffolding, which can be used for any code generation (not only ASP.NET MVC).

It is based on T4 but adds some usefull features like template parameters, integration with VS (opening documents, etc.), PowerShell scripting, and multiple files generation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top