Constantin Treiber
Constantin Treiber

Reputation: 420

IEnumerable T4 Templates

I'm working on some code-generation stuff - using T4 RuntimTemplates. I do have more than one template and I "store" them in an IEnumerable list.

My problem is that I want to iterate through the templates using .WriteAllText() which is a virtual method.

I thought, that it might be the easiest way to create an interface with the definition of .WriteAllText() and declare it in the partial class..

public partial class SolutionTemplateRunTime : SolutionTemplateRunTimeBase, ICodegenerationTemplate
{

This works till I store or update the template ;-) . The partial class (the code behind cs) of the template gets updated and the interfaces declaration is gone.

public partial class SolutionTemplateRunTime : SolutionTemplateRunTimeBase
{

Is there a solution to handle that? Its kind of annoying to redeclare the interface whenever I update the template..

Hope you can help..

Greetz Iki

Upvotes: 0

Views: 199

Answers (1)

Luaan
Luaan

Reputation: 63772

I think you're missing the point of partial - the idea is that exactly the kind of changes you want to do are done in a separate file - one that isn't generated.

Just create a new cs file, with a declaration like this:

public partial class SolutionTemplateRunTime : ICodegenerationTemplate
{
  ...
}

When compiling the code, the compiler will merge all partial declarations of the same class - this includes whatever interfaces the class implements etc.

Upvotes: 3

Related Questions