Book a Demo

Author Topic: find base classes  (Read 4193 times)

Maggie

  • EA User
  • **
  • Posts: 106
  • Karma: +0/-0
    • View Profile
find base classes
« on: April 20, 2012, 01:15:43 am »
Hi
Within my addin I am trying to find all the base classes for a given class.

so far I have
Code: [Select]
           foreach (EA.Connector connector in element.Connectors)
            {
                 if (connector.Type == "Generalization")
                {
                    EA.Element clientElement = Repository.GetElementByID(connector.ClientID);
                }
            }
This gives me a list of all Generalization connectors, including classes that derive from the target class.
What I need is only the classes from which the target class in derived.

I would be grateful if someone could give me some pointers

Thanks

Maggie

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: find base classes
« Reply #1 on: April 20, 2012, 01:49:05 am »
Hi,

Check SupplierEnd, ClientEnd properties of the connectors (not sure which one actually) to filter out those connected on the 'right' end.

HTH
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: find base classes
« Reply #2 on: April 20, 2012, 03:12:00 am »
you can se this method.

Code: [Select]
public static ArrayList getBaseClasses(EA.Element classToGet, ArrayList returnList)
{
      EA.Element actClass = classToGet;
      returnList.Add(actClass);
      foreach (EA.Element actBaseClass in actClass.BaseClasses)
      {
          returnList = getBaseClasses(actBaseClass, returnList);
      }
      return returnList;
}

to use this method:

Code: [Select]
ArrayList classAndParents = getBaseClasses(classToFindParents, new ArrayList());
« Last Edit: April 20, 2012, 03:12:53 am by stao »

Maggie

  • EA User
  • **
  • Posts: 106
  • Karma: +0/-0
    • View Profile
Re: find base classes
« Reply #3 on: April 20, 2012, 04:46:52 pm »
Thanks!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: find base classes
« Reply #4 on: April 23, 2012, 09:33:09 pm »
My implementation is at https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/ElementWrapper.cs basically the same:
Code: [Select]
   /// EA provides a shortcut tot the superclasses through its
    /// element.BaseClasses
    /// Normally we would get those via the element.generalizations.general
    public HashSet<UML.Classes.Kernel.Class> superClasses {
      get {
        return new HashSet<UML.Classes.Kernel.Class>
          (this.model.factory.createElements(this.wrappedElement.BaseClasses)
          .Cast<UML.Classes.Kernel.Class>());
      }
      set { throw new NotImplementedException(); }
    }