Customizing MSDataSetGenerator output in VS2005

S

Stig Nielsson

Hi,


I am using a strongly typed dataset in .Net 2.0, and would like all
tables to inherit from a cusomt datatable class instead of DataTable.
The reason for this is that I want some common code excuted on the row
events, and this I want to implement this once in a Table base class.


ie. instead of having this code generated:


public partial class ActivitiesDataTable : System.Data.DataTable,
System.Collections.IEnumerable {


I would like the tables to inherit from MyDataSet like this:


public partial class ActivitiesDataTable : CustomDataTable,
System.Collections.IEnumerable {


1) How can this be achieved. Is it possible to create a custom
generator that inherits from the MSDataSetGenerator, and override the
parts where the nested table classes are generated ?


2) In what assembly can I find the MSDataSetGenerator to do this?


3) Now that .Net 2.0 MSDataSetGenerator uses partial classes for the
DataSet, table and row classes, I could add my code without having it
overridden, but then I would have to edit each and every table and row
class in the generated dataset.


4) What is the best solution to customize the generated typed datasets
?


Regards


Stig Nielsson
 
N

Nicholas Paldino [.NET/C# MVP]

Stig,

This article should help you. It tells you how to generate code with
custom generators:

http://www.drewnoakes.com/snippets/WritingACustomCodeGeneratorToolForVisualStudio/

You could easily call into the MSDataSetGenerator tool, parse the code,
and replace where needed.

You can also try this:

http://www.raboof.com/Projects/VsCodeGeneratorShim/VsCodeGeneratorShim.aspx

Either way, you should call the old code generator, get the code, and
then pass it to CodeDom. Then, you can change your code, output it, and
then send it back.

You are going to take a hit doing this though, since the code will be
constructed, torn apart, then reconstructed again.

Hope this helps.
 
S

Stig Nielsson

thanks for the answer - it looks as a promising idea.

I succeeded in creating and registering a custom code generator, and it
works in VS2005. Now I would like this generator to invoke the
MSDataSetGenerator to get its generated code, but I dont know how to
achive this (as I don't have much COM experience).

Should I create a reference to a COM object in my project? I have tried
doing this, but cannot find any com object that is called
MSDataSetGenerator

So when you write

"Either way, you should call the old code generator, get the code, and
then pass it to CodeDom. Then, you can change your code, output it,
and
then send it back. "

how should I do this?

regards

Stig Nielsson
 
S

Stig Nielsson

The Xsd.exe tool in the SDK generates the same dataset code as
MSDataset generator, so one solution to my questions above could be to
fork of a process in my generator to create a temporary dataset file,
which I then somehow load into a CodeDom which I then can modify and
write to a souce file.

I am pretty sure this would work, but it seems a bit clumsy. Does any
one have a better idea ?

regards

Stig Nielsson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top