Book a Demo

Author Topic: C# Interop API: Stereotype from mdg tech not applied to EnumerationLiteral  (Read 3215 times)

Hauke Wittern

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
I am using the C# interop API to create elements and apply stereotypes from my custom MDG Technology. This works fine for classes and properties but not for enumeration literals.

The following code snippets illustrates what I try to do:
Code: [Select]
private EA.Attribute CreateExampleLiteral(EA.Element enumeration, string name)
{
    Debug.Assert(enumeration.Type == "Enumeration");

    var literal = (EA.Attribute)enumeration.Attributes.AddNew(name, null /* literal has no type */);
    literal.StyleEx = "IsLiteral=1;";
    literal.StereotypeEx = "my::ExampleStereotype";
    // Now literal.StereotypeEx and literal.FQStereotype are not "my::ExampleStereotype" as I would expect.
    literal.Update();

    Repository.SynchProfile("my", "ExampleStereotype");
    return literal;
}
ExampleStereotype is a stereotype that extends meta class EnumerationLiteral.
Quite similar code for properties works as expected (i.e. add EA.Attribute owned to a class element, apply different stereotype and StyleEx not set).

Is this a bug or do I miss something?


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: C# Interop API: Stereotype from mdg tech not applied to EnumerationLiteral
« Reply #1 on: February 16, 2021, 05:47:20 am »
Have you tried

Code: [Select]
var literal = (EA.Attribute)enumeration.Attributes.AddNew(name, "my::ExampleStereotype");
literal.Update();

That should do the trick. I've never tried this with enumerationLiterals though.

A possible workaround could be to use a Stereotype that extends Attribute instead of EnumerationLiteral.

Geert

Hauke Wittern

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: C# Interop API: Stereotype from mdg tech not applied to EnumerationLiteral
« Reply #2 on: February 16, 2021, 06:16:26 am »
Code: [Select]
var literal = (EA.Attribute)enumeration.Attributes.AddNew(name, "my::ExampleStereotype");
literal.Update();

Unfortunatelly, that does not work. StereotypeEx and FQStereotype are still empty. Many thanks, though. Your suggested workaround will do it.