Customizing MSDataSetGenerator output in VS2005

Discussion in 'Microsoft C# .NET' started by Stig Nielsson, Dec 6, 2005.

  1. 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
     
    Stig Nielsson, Dec 6, 2005
    #1
    1. Advertisements

  2. 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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    -

    "Stig Nielsson" <> wrote in message
    news:...
    > 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
    >
     
    Nicholas Paldino [.NET/C# MVP], Dec 6, 2005
    #2
    1. Advertisements

  3. 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
     
    Stig Nielsson, Dec 7, 2005
    #3
  4. 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
     
    Stig Nielsson, Dec 8, 2005
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VR

    Customizing FlexGrid w/ a check box

    VR, Aug 31, 2003, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    416
  2. Bui Trung Nguyen

    Datagrid Customizing

    Bui Trung Nguyen, Sep 16, 2003, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    175
    William Ryan
    Sep 16, 2003
  3. Guest
    Replies:
    3
    Views:
    375
    Guest
    Apr 21, 2004
  4. mike
    Replies:
    5
    Views:
    296
    Willy Denoyette [MVP]
    Dec 1, 2005
  5. Guest

    Loading Aximp output files into Vs2005 Tools

    Guest, Aug 13, 2006, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    198
    Guest
    Aug 13, 2006
Loading...

Share This Page