cs0815
cs0815

Reputation: 17428

code generation from UML class diagram

I have a UML class diagram with 2 classes A and B in enterprise architect (example simplified). The class diagram shows an association between A and B. The association is 0..1 To 0..m for A and B respectively. This means that A can have 0 ... m B instances and B belongs to 0 or 1 A instance. I generated this C# code with the enterprise architect (simplified):

class A
{
   public B _b;
}

class B
{

}

However, shouldn't it rather be:

class A
{
   public IList<B> _bs;
}

class B
{

}

Is there anything I have to consider during code generation (I also selected both classes and than generated the code without success).

Upvotes: 2

Views: 2747

Answers (2)

Uffe
Uffe

Reputation: 10514

Go to Tools - Options - Source Code Enineering - C# and click the Collection Classes button to specify the collection classes used for code generation (ignore the 1..* label).

You specify multiplicity properties (ordered etc) in the connector's Properties, on the Target Role tab (I'm pretty sure EA will ignore the 0..1 multiplicity on the Source Role; there isn't really a lot it could do with it).

Finally, make sure all your classes and packages are specified as C#. Easiest way is to right-click the package in the project browser and select Code Engineering - Reset Options for this Package, then in the dialog specify "Where language is <All>", "Convert to C#" and Process Child Packages.

Upvotes: 2

chimp
chimp

Reputation: 1849

You need to define which collection class you want the code generation to use. It is, from memory, Tools > Options > Code Engineering > C#

Upvotes: 1

Related Questions