Vaibhav Jain
Vaibhav Jain

Reputation: 34407

Usecases of runtime text generation using Preprocessed T4 Text Templates

I understand what is a T4 template and its type i.e design time and runtime time. I also understand where design time text generation can be used.
But I can't really comprehend the usecases of the runtime generation of the text. Can it be used to generate code at runtime.
Please enlighten me.

Upvotes: 1

Views: 549

Answers (1)

GarethJ
GarethJ

Reputation: 6606

Runtime text templates can be used to embed generation in an application that cannot take a dependency on Visual Studio.

A typical enterprise application example of where this might be used is to embed a pro-forma HTML email into a web application. This would a case be where its acceptable for the template not to change other than on application deploy boundaries, but the data itself does change.

The other key application is for toolkits or libraries that want to have T4 code generation with a default template that does not rely on Visual Studio. The Entity Framework is the canonical example here. It needs to do code generation but cannot rely on Visual Studio being installed as it is part of the .Net framework. So it uses runtime templates to provide default code generation, and then allows design-time templates to be used to override its default behavior.

Upvotes: 2

Related Questions