This project is read-only.

Breaking change needed to support preprocessed templates in VS 2010

Sep 30, 2009 at 11:55 AM

We may need to introduce a breaking change in the Template class to support preprocessed templates in Visual Studio 2010. Currently, Template overrides and seals the TransformText methods and declares a new abstract method called RenderCore. Unfortunately, this prevents us from using Template as a base class for preprocessed templates in VS 2010, which always generate an overridden TransformText method.

For the new release, I am thinking about changing Template class to leave TransformText method abstract, mofe all of its logic to the Render method and get rid of RenderCore. This would make the design of this class compatible with preprocessed templates in 2010, but would break existing code that overrides RenderCore. The fix would be simple - replace RenderCore declaration with TransformText and make the method return this.GenerationEnvironment.ToString() because RenderCore was void and TransformText has to return a string.

I hate introducing breaking changes and I wish I could see this coming last year, however, support for preprocessed templates is simly too nice in 2010. What do you think? Are there any other ways to get around this?

Sep 30, 2009 at 1:51 PM

Oleg --

Regarding the change that would be required to existing code...

>>>The fix would be simple - replace RenderCore declaration with TransformText and make the method return this.GenerationEnvironment.ToString() because RenderCore was void and TransformText has to return a string.

...that change sounds fine to me, I think, if the change to existing code is as I think it is-- minimal.

Can you explain a bit more from an implementation-level exactly what actual code changes would be needed to existing templates?

Is it as simple as changing this...
protected override void RenderCore()
...to this...
protected override string TransformText()
{
...blah
return this.GenerationEnvironment.ToString();
}
...???

For example, I have the following...

The file "_T4CodeUtility02File.tt" includes/uses the file "_T4CodeUtility02Generator.tt".

The file "_T4CodeUtility02Generator.tt" includes/uses the file "_T4CodeUtility02Template.tt".

The code is something like the following.

Inside "_T4CodeUtility02File.tt" I call...
myGenerator.Run();

Inside "_T4CodeUtility02Generator.tt" I have...
protected override void RunCore()
...and...
myCodeUtility02Template.RenderToFile(myFileNameTemp);

Inside "_T4CodeUtility02Template.tt" I have...
protected override void RenderCore()

...and that works fine.

So, my understanding is that inside "_T4CodeUtility02Template.tt" I replace this...
protected override void RenderCore()
...with this...
protected override void TransformText()
...and inside "TransformText()" I would call...
this.GenerationEnvironment.ToString()
...at the end??? Or where?

(My reference implementation is my most recent "Northwind01_T4Sample_" at the link http://t4toolbox.codeplex.com/SourceControl/PatchList.aspx where the Patches are.)

Thank you.

-- Mark Kamoski

Sep 30, 2009 at 8:56 PM

Mark,

Yes, you would replace "protected override void RenderCore()" in your code with "public override string TransformText()" and add "return this.GenerationEnvironment.ToString()" at the end.

We could also mark RenderCore as obsolete, but keep it working for traditional T4 Toolbox templates for a while to let people make this change at their own pace.

Oleg

Sep 30, 2009 at 9:51 PM

Oleg --

Regarding this...

>>>Yes, you would replace "protected override void RenderCore()" in your code with "public override string TransformText()" and add "return this.GenerationEnvironment.ToString()" at the end.

...that is easy as pie. No sweat here. FWIW. The caveat is that it must still work in VS.NET 2008 too. Without that, I am sunk.

Regarding this...

>>>We could also mark RenderCore as obsolete, but keep it working for traditional T4 Toolbox templates for a while to let people make this change at their own pace.

...I would vote "no" on this idea unless it is required to keep it working in VS.NET 2008, in which case I would vote "yes". (My current situation is such that the team will not be moving to VS.NET 2010 right away, which is a sad reality for me. Ug. That's another story.)

HTH.

Thank you.

-- Mark Kamoski

Nov 2, 2009 at 6:59 PM
olegsych wrote:

...replace "protected override void RenderCore()" in your code with "public override string TransformText()" and add "return this.GenerationEnvironment.ToString()" at the end.

That works perfectly.

Thank you.

-- Mark Kamoski