Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: blackpuppy on March 30, 2005, 01:50:36 am

Title: automatically generated attribute for relationship
Post by: blackpuppy on March 30, 2005, 01:50:36 am
I have a Currency class.  It has a private _rates attributes of the type ExchangeRateCollection that is a list of ExchangeRate objects.  In addition, I have a class diagram that specify the 1-to-many relationship(link) between Currency and ExchangeRateCollection.

Then when I generate the C# code, it will generate the private _rates attribute and this is correct.  But in addition, it will generate a public attribute m_ExchangeRateCollection of type ExchangeRateCollection.  The relevant code snippet is quoted below.

Code: [Select]

public class Currency
{
   ! other code omitted

   private ExchangeRateCollection _rates;
   public ExchangeRateCollection m_ExchangeRateCollection;

   ! other code omitted
}//end Currency


I think the latter attribute comes from the 1-to-many relationship.  In fact, I do not want this latter public attribute.

How to avoid the latter attribute generated from the relationship(link)?  I can delete the class diagram or just delete the link from the Currency class' property window/Link tab.  And it works.  But is this the only solution?  Or I can change the classes in the class diagram to objects, and this also works but it is a little strange.

Has anybody met the similar problem?  Any other solution?

Thanks!
Title: Re: automatically generated attribute for relation
Post by: Eve on March 30, 2005, 02:26:24 pm
EA is generating this attribute by design, but there a couple of ways that you should be able to stop it.

Under Tools | Options | Generation there are two options that can stop it under different circumstances.

Firstly, "Auto generate role names when creating code" can be unchecked and EA shouldn't generate an attribute if there is no role name (because it doesn't have a name for the attribute.)  However, I just discovered that this option doesn't work at the moment (fixed for build 751 :)) so we'll move on to option two.

"Do not generate members where association direction is 'Unspecified'".  Check this and if the option fits what you want.

If neither of those work and you don't want any attributes generated from the attributes, go into the template editor (Configuration | Code Generation Templates) and clear the Linked Attribute template for C#.

Simon
Title: Re: automatically generated attribute for relation
Post by: blackpuppy on March 30, 2005, 06:22:14 pm
Thanks, Simon! :)

I just tried the options in build 750.  As you said, there is a bug with option 1.

For option 2, I found the option was unchecked before.  So I guess it does not fit my case.

I'll be waiting for build 751.

For the time being, I'll disable the Linked Attribute template for C# by putting %endTemplate% in the first line.  There may be another bug here.  When I delete the template and press Save button, the default template will come back.  ???

Thanks!
Title: Re: automatically generated attribute for relation
Post by: Eve on March 31, 2005, 02:08:38 pm
The second option needs to have the checkbox checked.  Not unchecked.

The template problem is that EA is displaying the default template in preference to an empty user defined template.  The positive side to this is that at least the user template is being saved correctly and used in code generation.

It will be fixed for build 751 though.