Sign In
[Profoundly Esoteric Image]
GarethJ's WebLog - Code generation and abstraction
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
RSS for comments
Search
Advanced search options...
Search In:
Everything
Blogs
Forums
People
Groups
Places
Pages
Date range:
All Time
Last Year
Last 6 Months
Last 3 Months
Last Month
Last Week
Last Two Days
Tags
Built with DSL Tools
Code Generation
Code samples
Community
DSL Tools
Enterprise Development
Fun
Metablog
Modeling
Pages
Razor
Sounding off
SP1
T4
Tech thrills
The real world
UML
Visual Studio
Visual Studio 11 Beta
VSX
Archive
Archives
April 2012
(1)
November 2011
(1)
September 2011
(1)
June 2011
(1)
May 2011
(1)
April 2011
(1)
March 2011
(2)
January 2011
(6)
December 2010
(2)
August 2010
(1)
June 2010
(1)
April 2010
(2)
March 2010
(1)
October 2009
(1)
September 2009
(6)
May 2009
(3)
February 2009
(4)
January 2009
(2)
November 2008
(6)
October 2008
(5)
September 2008
(3)
July 2008
(2)
May 2008
(4)
April 2008
(4)
March 2008
(2)
February 2008
(9)
January 2008
(9)
December 2007
(6)
November 2007
(1)
October 2007
(3)
September 2007
(5)
August 2007
(3)
July 2007
(3)
June 2007
(5)
May 2007
(6)
April 2007
(1)
March 2007
(2)
February 2007
(5)
January 2007
(3)
December 2006
(2)
November 2006
(2)
October 2006
(3)
September 2006
(3)
August 2006
(2)
July 2006
(2)
June 2006
(5)
May 2006
(1)
April 2006
(3)
March 2006
(1)
February 2006
(3)
January 2006
(3)
December 2005
(10)
November 2005
(5)
October 2005
(3)
September 2005
(8)
August 2005
(2)
July 2005
(4)
June 2005
(5)
May 2005
(6)
April 2005
(2)
March 2005
(4)
February 2005
(4)
January 2005
(5)
December 2004
(9)
November 2004
(4)
October 2004
(13)
August 2004
(4)
July 2004
(2)
Breaking changes to T4 Text Templating in the September DSL Tools CTP
MSDN Blogs
>
[Profoundly Esoteric Image]
>
Breaking changes to T4 Text Templating in the September DSL Tools CTP
Breaking changes to T4 Text Templating in the September DSL Tools CTP
GarethJones
20 Sep 2005 5:19 PM
Comments
1
We've made a couple of breaking changes to the interfaces exposed by our text templating engine in this CTP in the area of directive processors.
These won't affect regular DSL Tools users, as after going through the May-September migration process your code will just work. (Note, all May CTP DSL Tools users MUST migrate their previous projects to use the September CTP successfully with them).
However, for those adventurous souls who've written their own directive processors (yes, you
DuncanP
), there may well be a little work to do.
The problem we've addressed occurs when you use multiple custom directives in a single template, processed by one or more directive processors.
Each of these directives typically needs a way to contribute some code to the generated transformation class that T4 produces and executes in order to spit out the final text stream.
For example, multiple directive processors need a way to add one method call for each directive and for this method to be called at a predictable time. This wasn't previously easy to achieve.
We've added two abstract methods to the DirectiveProcessor base class...
/// <summary>
/// Get the code to contribute to the body of the initialize method of the generated
/// template processing class as a consequence of the most recent run.
/// This code will run before the base class' Initialize method
/// </summary>
public abstract string GetPreInitializationCodeForProcessingRun();
/// <summary>
/// Get the code to contribute to the body of the initialize method of the generated
/// template processing class as a consequence of the most recent run.
/// This code will run after the base class' Initialize method
/// </summary>
public abstract string GetPostInitializationCodeForProcessingRun();
These methods supply code to be added to the body of the Transformation class' Initialize method. As you'd expect from the names, code from the first method get added before the call to base.Initialize() and code from the second gets added after the call. This allows you to set up some data in the "Pre" code, process that data in a custom TextTransformation base class and then do something else with it in the "Post" code.
All this is a bit abstract. To pick a concrete example, here's pseudo-code for how the DSL Tools' supplied directive processors use this functionality:
class CustomTransformBase
{
protected List<SubStore> domainModelsToLoad = new List<SubStore>();
public void Initialize()
{
Store.LoadSubStores(MakeUnique(this.domainModelsToLoad));
}
}
class GeneratedTransformationClass
{
public void Initialize()
{
domainModelsToLoad.Add("RequiredDomainModel1forDirective1"); // Added by GetPreInitializationCode
domainModelsToLoad.Add("RequiredDomainModel2forDirective1"); // Added by GetPreInitializationCode
domainModelsToLoad.Add("RequiredDomainModel1forDirective2"); // Added by GetPreInitializationCode
domainModelsToLoad.Add("RequiredDomainModel2forDirective2"); // Added by GetPreInitializationCode
base.Initialize();
Store.LoadModel("ModelSpecifiedByDirective1"); // Added by GetPostInitializationCode
Store.LoadModel("ModelSpecifiedByDirective2"); // Added by GetPostInitializationCode
}
For those of you who build on top of the RequiresProvidesDirectiveProcessor, this cascades through to two new methods there to do the same sort of thing…
/// <summary>
/// Method for derived classes to contribute additively to initialization code for the TextTransformation generated class.
/// </summary>
/// <remarks>
/// Additive code is useful where there are multiple directive processor instances each needing to have some instance-specific initialization.
/// As GenerateTransformCode can add methods, matching initialization code is often required to call those methods.
/// This code will be added before the call to the base class.
/// </remarks>
protected abstract void GeneratePreInitializationCode(string directiveName, StringBuilder codeBuffer, CodeDomProvider languageProvider, IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments);
/// <summary>
/// Method for derived classes to contribute additively to initialization code for the TextTransformation generated class.
/// </summary>
/// <remarks>
/// Additive code is useful where there are multiple directive processor instances each needing to have some instance-specific initialization.
/// As GenerateTransformCode can add methods, matching initialization code is often required to call those methods.
/// This code will be added after the call to the base class.
/// </remarks>
protected abstract void GeneratePostInitializationCode(string directiveName, StringBuilder codeBuffer, CodeDomProvider languageProvider, IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments);
Next time, I'll discuss how this affects the ModelingTextTransformation base class which has changed somewhat because of these changes.
1 Comments
Modeling
,
Code samples
,
DSL Tools
,
T4
Blog - Comment List MSDN TechNet
Comments
Loading...