Book a Demo

Author Topic: Automatically adding using namespaces  (Read 5315 times)

jmichelson1

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Automatically adding using namespaces
« on: February 08, 2004, 02:44:37 pm »
This message is for Sparx technical support:

It seems that the code generator (C#) is not smart enough to add "using..." statements based on the types that appear in the body of the class.  For example, if the class has the following declaration "private AccountType _account", and the "AccountType" is defined in the "Business.DataTypes" assembly (and appears as such in EA), than the "using Business.DataTypes" shoulod be automatically added to the declarations.  But, it doesn't.

I would think that this should be basic functionality.  Am I wrong?

Thanks... Jeff

random12345

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #1 on: February 09, 2004, 03:07:51 am »
I can see a problem if namespaces were used automatically for C++ at least.
We're involved in embedded programming and, as such, use a subset of C++ called EC++.  This subset is an industry standard, used by many and does not support the use of namespaces (or templates).  Thus we would prefer they were not added automatically  :)

You could argue that EC++ should be individually.  I prefer the idea of a series of switches that turn-off certain language support eg. namespaces.  This way we are more flexible as the standards (and chosen library sets) change.

fluxtah

  • EA User
  • **
  • Posts: 144
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #2 on: February 09, 2004, 05:07:47 am »
The 'using' statement does appear for forward engineering of c# code.

From my experience, the View is the top level namespace (by default), ie if you call one of your views, Business, then within this view a new package called DataTypes, then create a class within DataTypes.

outside of the Business package (top view package) make a new package and a new class, with reference to the dataype, EA, on forward engineer,  should output the correct 'using' statements.

- Fluxtah

jmichelson1

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #3 on: February 09, 2004, 11:47:07 am »
Quote
... on forward engineer,  should output the correct 'using' statements.


Perhaps it should, but it DOESN'T.  Would a Sparx technician PLEASE respond to this post?  It's my second one.

- J

fluxtah

  • EA User
  • **
  • Posts: 144
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #4 on: February 09, 2004, 12:19:09 pm »
Hiya,

Excuse my speculative reply, I was at work and have not got EA there yet.

By creating an association link betweent the 2 classes you can get the using statement into your fwd engineer.



which creates the following code

Code: [Select]

///////////////////////////////////////////////////////////
//  ClassA.cs
//  Implementation of the Class ClassA
//  Generated by Enterprise Architect
//  Created on:      09-Feb-2004 20:03:20
///////////////////////////////////////////////////////////




using RootB;


namespace RootA {
     public class ClassA {

           private ClassB classB;

           public ClassA(){

           }

     }//end ClassA
}//end namespace RootA


In my diagram I did add an attribute to Class A but it was unecessary as EA generates this also when the target role is specified on the connector.

regards

- Fluxtah

fredhirschfeld

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #5 on: February 09, 2004, 12:54:37 pm »
I am having the same problem and what was mentioned here does work IF you are using an association.

I was trying to use an Interface by dependency from another package and expected that the proper using would get put in place, but it didn't. I also tried doing various things to force this using the package vs the interface and nada!

After reverse engineering the other sample code I noticed an area to keep the using code. You need to right-click on the class and press CTRL-G for the generation dialog. The two textboxes are used to type in some code that is used at the start of the module.

Code: [Select]
using System;
using System.Data;


I don't like having to do this but it is the only way I can tell to actually get the using statements done (aside from the associations).

Fred
« Last Edit: March 16, 2004, 10:23:16 pm by Newman »

jmichelson1

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #6 on: February 09, 2004, 07:45:40 pm »
I have to say... this seems like a pretty huge oversight for such a mature product!  Does Sparx monitor this newgroup?  What say you?

- J

fredhirschfeld

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #7 on: February 10, 2004, 07:44:11 pm »
In another area, benc (EA Administrator) indicated that this was going to be worked on in future releases. He indicated that the presence of a "used" type in the EA model will cause the proper Using statement to be generated.

I assume this means both return types as well as parameter types.

Fred

benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #8 on: February 11, 2004, 03:48:12 pm »
Confirmed ... similarly for field types.

A note: the using statements would be generated for initial code generation only. Currently, using statements are not synchronized.

Regards,
Ben

fluxtah

  • EA User
  • **
  • Posts: 144
  • Karma: +0/-0
    • View Profile
Re: Automatically adding using namespaces
« Reply #9 on: February 12, 2004, 03:19:35 am »
Cool cheers Ben, thanks for the note.

- Fluxtah