Book a Demo

Author Topic: List Property keeps being regenerated as an attribute - How to prevent?  (Read 12879 times)

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
For some reason some (several) list attributes which I turned into Properties, keeps being regenerated as List attribute again, causing conflict (due to duplicate identifiers).

Illustrated below the Property "CoElements" is re-generated as a list attribute even if I delete it in the code and synchronize the code back up to EA. But when generating code the next time, that evil attribute is back in the code again. I have several of these cases, which requires manual clean up.

Q: Is there any way I can prevent EA from regenerating such extra attribute copies of what should only be a property? (plus its inner member).

Quote
public List<Co_Element> CoElements;     // Attribute keeps being regenerated - Irritating

private List<Co_Element> _CoElements; // "Inner member" as intended - OK

public List<Co_Element> CoElements;    // Property as intended - OK
{
    get
    {
        if (_CoElements == null)
            _CoElements = new List<Co_Element>();
        return _CoElements;
    }
}

//Rolf
« Last Edit: February 21, 2024, 11:07:52 am by RIL »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #1 on: February 21, 2024, 11:16:46 am »
What does your model look like? What changes have you made to the code templates? If you do something equivalent with the original templates how does it behave?

Basically, the Code Templates that you can change are in balance with the grammars defined for the importer, which you can't change. If you change the code templates to generate something that doesn't match what the importer sees you will get this behavior. The only ways to prevent it are either to not make those changes or not reverse engineer the model from the code after it's generated.

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #2 on: February 21, 2024, 01:28:28 pm »
What does your model look like?

Very simple. A few more lines than I already posted (it's just a small test case for some ideas I'm testing).

What changes have you made to the code templates?

None. Just to make sure nothing spooky were lurking in the code templates, I created a new EA model (100% guaranteed untouched code template) and imported and generated, and the same happened again.

But, I noticed something strange with the newly imported model - it had two copies of the class which had the problematic links. That explains it. So I deleted the dupe and generated code, and the sun is shining again.

And no, I had NOT copied that class, at least not consciously. That copy was not visible in the Project Browser on the original model. Only now, when I imported the model into a new EA project, then EA put both copies on a auto-diagram and also showing the two classes in the Project Browser.

Basically, the Code Templates that you can change are in balance with the grammars defined for the importer, which you can't change. If you change the code templates to generate something that doesn't match what the importer sees you will get this behavior.

I honestly don't think so. As long as I have valid C# code (compiling in VS) I have so far not had any problem with EA importing it. Which means that EA knows the grammar, and no matter what kind of code I would generate with a modified template (which compiles in VS), EA seems to pick it up. No connection there.

Or if I put it another way; I do not make templates which produces invalid C# code which neither VS nor EA can  handle.

The only ways to prevent it are either to not make those changes or not reverse engineer the model from the code after it's generated.

Hm, that doesn't seem to be irrelevant. What's relevant is that the C# code is valid. Well, so far EA 16.1 has handled import without any problem.

What I have noticed though is that sometimes EA doesn't show what it has in the database.  For example the Delphi project I posted about which had some 16.300 .pas files. I had to close EA and start it again before any of the ~20.000 classes would show in the Project Browser. Reminds about this problem where the Project Browser didn't bother show me I had a copy of a class (must have pressed CTRL-C, CTRL-V when not having focus in the right place... or something).

The developers would have reasons to  investigate why the UI doesn't always reflect the data...

//Rolf
« Last Edit: February 21, 2024, 01:33:11 pm by RIL »
-- There's always a solution --

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #3 on: February 21, 2024, 03:24:36 pm »
Hm. After I restarted the EA Model (after importing the code into a new model) the link-problems are back again.

Had this been a problem with Rhino3d and me posting about it on their Forum, then one of the developers would have asked for a stripped down test project in order to hunt down the problem.

Anyway, something seems to get messed up in the database. Code example again below; A List Property insists on being reintroduced as a Link attribute, disregarding the fact that the Property with the same name already exist.

//Rolf

Quote
   private CoObject _CoClassMemberInfo;
   public CoClassMemberInfo CoClassMemberInfo; // <-- This sneaks in again and again...
   public CoClassMemberInfo CoClassMemberInfo
   {
      get
      {
         if (_CoClassMemberInfo == null)
            _CoClassMemberInfo = new CoClassMemberInfo();
         return (CoClassMemberInfo)_CoClassMemberInfo;
      }
      set
      {
         Debug.Assert(false, "The CoClassMemberInfo property is read only");
      }
   }
-- There's always a solution --

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #4 on: February 21, 2024, 09:10:50 pm »
Think about scripting the whole thing yourself. I did so years ago and it's by far easier than struggling with EA's pseudo-script oddities.

q.

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #5 on: February 22, 2024, 03:10:36 am »
Think about scripting the whole thing yourself.
q.

I definitely have thought of it, but at this time I'm only testing out some little idea I have and so I won't have the time to start from scratch. I had hoped EA would have supported at least the most basic of tings.

Q: Anyway, can the code templates call external scripts (so I could at least do some point fixes here and there?)

//Rolf
-- There's always a solution --

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #6 on: February 22, 2024, 09:30:00 am »
No idea since I do not touch that awkward stuff...

q.

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #7 on: February 22, 2024, 12:42:53 pm »
No idea since I do not touch that awkward stuff...
q.

I begin to understand what you mean. :)

//Rolf
-- There's always a solution --

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #8 on: February 22, 2024, 07:26:45 pm »
Q: Anyway, can the code templates call external scripts (so I could at least do some point fixes here and there?)

//Rolf

IIRC there is indeed a way to call an add-in function.
I found this snippet somewhere on this forum. I never used it myself though.

$opCode = %EXEC_ADD_IN("CS_Addin", "GetSignals", classGUID, classStereotype, ...)%

Geert

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: List Property keeps being regenerated as an attribute - How to prevent?
« Reply #9 on: February 23, 2024, 05:46:36 pm »
IIRC there is indeed a way to call an add-in function.
I found this snippet somewhere on this forum. I never used it myself though.

$opCode = %EXEC_ADD_IN("CS_Addin", "GetSignals", classGUID, classStereotype, ...)%

Geert

Thanks of that hint, I will definitely look into that!

//Rolf
-- There's always a solution --