Book a Demo

Author Topic: Indexed parameter compatibility issues in EA_PreNewElement  (Read 3299 times)

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Indexed parameter compatibility issues in EA_PreNewElement
« on: March 24, 2018, 04:51:22 am »
Hi all,

due to having had now incompatibility issues on three version changes of EA (11->12, 12->13, 13->13.5), I wanted to make the knowledge explicit, how to circumvent these issues.

The affected method was the EA_OnPreNewElement broadcast event with its signature
Code: [Select]
bool EA_OnPreNewElement(IDualRepository repository, EventProperties info)The EventProperties parameter is a class that contains a list of arbitrary data that can be accessed by
Code: [Select]
EventProperties.Get(object Index)This class is used as parameter in several of EA's broadcast events.

The problem with the usage of this class is that there are two ways of accessing the data in the event properties: either by passing a zero-based index to access a certain value in the list Props.Get(3) or by using a string identifier for the content which should be retrieved Props.Get("ObjectID").

If you use the index-based access (like I did since the beginning of my add-in writing. Don't even know, if the associative access was possible back then), you have to rely on the fact that the order of contents in the event properties is not changed.
Following is a small history of the event properties content and order in EA_OnPreNewElement:
EA 11:
0 Type 1 Stereotype 2 ParentID 3 DiagramID
EA 12:
0 Type 1 Stereotype 2 ParentID 3 DiagramID --> the parent ID delivered in EA12 is not anymore the direct element the element was dragged to, but the outmost parent element in the diagram
EA 13:
0 Type 1 FQStereotype 2 Stereotype 3 ParentID 4 DiagramID --> FQStereotype inserted in the middle of the list
EA 13.5:
0 Type 1 ParentID 2 DiagramID 3 Stereotype 4 FQStereotype --> Stereotype and FQStereotype moved to the end of the list

Without commenting this observation further, only two recommendations :):
  • To add-in developers: Only use the associative access to the event properties list (Props.Get("ParentID")), as hopefully the identifiers will stay the same for coming EA versions.
  • To the Sparxians designing the add-in interface: In the future, please make sure to add new parameters to the end of the list so that you will not cause incompatibilities in newer EA versions and don't change the order if there is no good reason for it. Alternatively, deprecate the index-based getter method in the EventProperties class.

Just my two cents on the topic
Jan
« Last Edit: March 24, 2018, 04:52:54 am by McMannus »