Book a Demo

Author Topic: VBNET Class/Module code generation  (Read 2481 times)

ea0804

  • Guest
VBNET Class/Module code generation
« on: September 24, 2004, 04:25:39 am »
Hi there?

Is there a way to generate a Module in VB.NET?

I have to be honest with you... I tryied to change templates from class but it got confused ( Instead of classes it started to generate modules).

I saw something in see if class is from interface type, but how can I generate a module. That is my question.

If someone could help me.
« Last Edit: September 24, 2004, 08:15:38 am by ea0804 »

KiwiMitch

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: VBNET Class/Module code generation
« Reply #1 on: September 29, 2004, 05:42:23 pm »
Hi Plogis,

I just read your post because I was wanting to do the same thing.

I've come up with a way of doing it, not sure if it's the best way, but here goes:

1. Make a new stereotype called "module" (Config --> UML --> Stereotypes). Set the base class to Class and save.

2. Open the code generation templates (Configuration --> Code generation templates) and select VBnet as the language

3. Select 'Class Decleration' from the list of templates

4. Click 'Add new stereotyped override' and selet 'module' (this is the stereo type you just created). Leave 'Feature' blank.

5. Edit the code it generated. You need to find where it writes the word 'Class' For me it was the fifth row from the bottom "Class %className%\n". Replace 'Class' with 'Module' and save

6. Do the same for the 'Class Body' template (ie add the stereotype module and edit the code so it writes 'Module' instead of 'Class', for me this was the very last line of code). Save and close the dialouge.

And that's it. Now when you create a class, set its stereotype to 'module' and when it generates code it will generate a module instead of a class.

HTH

Mitch

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: VBNET Class/Module code generation
« Reply #2 on: September 29, 2004, 06:49:56 pm »
I would say it is the neatest way to do it.

It results in the easiest to read templates in my opinion.

Just so you know, it didn't generate any code, it just copied the standard template, which would have stuff that should never happen for your module stereotype.  You should safely be able to remove everything between
%if elemType = "Interface"%
and the matching
%endTemplate%
including those lines.

A different way of doing it is to check in the standard templates the class stereotype.  That would look something like this.

%if classStereotype == "module"%
Module %className%
%else%
Class %className%
%endIf%


This isn't as easy to read, but it does mean that there is less replication if you ever want to update the code that is common between them.  It also means that you don't need to do step 1.

Simon.