Hello guys,
The add-in project (C#) I'm working on is getting bigger, and it claims for some refactoring. One of the mean issues appointed by the developers is the amount of methods to handle EA functions with regards to their Objects.
I explain: right now, in our code, there are a lot of methods in the CreateX(Y _y, string name, string stereotype). For example:
CreateDiagram(Package p, bla, bla);
CreatePackage(Package p, bla, bla);
CreateElement(Package p, bla, bla);
CreateElement(Element e, bla, bla);
I call your attention for the numerous combinations possible, which turns to be impractical to handle... All those methods are static and have more or less the same shape:
CreatePackage(Package p, bla, bla){
var p = (Package)null;
try
{
p = inThis.Packages.GetByName(createThis);
}
catch
{
// inThis does not contain createThis
}
if (p == null)
{
p = inThis.Packages.AddNew(createThis, withThisType);
}
p.Update();
inThis.Packages.Refresh();
inThis.Update();
}
When we decided to do something about, we got stopped just in the begging. Some ideas were to Build a static class (say "EAHelper" with public, static methods (say Create *). But this approach simply does not work from the begging. We thought about using generics, something like:
public static void Create<T> (T obj, string name, string type){ }
But this won't work because a object T won't have a "Packages" or "Elements" list.
In summary, I'm asking for assistance in order to code a proper class to handle this EA packages, elements, objects, etc from the inside the c# code nicely. If something like this already exist, great! Please, advise. If not, I will do my best to make it as generic and public as possible, since it is very hard to find good programming material for EA.
Thanks in advance,
Pedro Dusso