Cull'log

Stefan Cullmann's Blogging

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

CodeGen

Blog roll

Nice to have

Code Generation

Subscriptions

Post Categories

Article Categories



Greenator Features: Visual Studio .Net integration

VS .NET has a built in interface for integrating Code Generation called custom tool. Two Custom Tools (also called Generators) come with VS.NET, MSDataSetGenerator for strongly-typed DataSets, and MSDiscoCodeGenerator for WebService proxy classes.

Once you have set the property custom tool the generator starts and generates a subordinate project item with the generated source. Every time you change and save your base definition file,  the source file is generated again.

I like the transparent way how the generation works. In fact, at first sight it is a miracle how the strongly typed dataset is generated from a Schema.

It is possible to write your own custom tools. All you need is to implement one function:

public override byte[] GenerateCode(string file, string contents)
{
string code = "<<generated code>>";
return System.Text.Encoding.ASCII.GetBytes(code);
}


On a second sight, this approach limits the scope for active code generation. Code generation should be under your control, you should e.g. set the templates to be used for the code generation. It is not possible to set a further argument inside the properties of the definition file.

Some code generators that implement custom tool cheat; they add the reference of the template inside the model definition. That is not orthogonal.

Furthermore it is not possible to generate two code files out of one model.

Greenator is written as Visual Studio Add-In and for this reason Greenator is not limited by the design of custom tool. But Greenator supplements custom tools behaviour, it watches all templates and models and generates the code file or even files transparent on the fly every time it must.

posted on Sunday, March 14, 2004 9:40 PM by stefan@cullnet.de





Powered by Dot Net Junkies, by Telligent Systems