Reputation: 507
Working with an add-in for Enterprise Architect (EA) I need to get all the different types a Test can have in EA.
By this I mean that the Test class in the EA namespace inherits from an IDualTest interface which has the get/set method for the string attribute named "Type". As a standard EA has 3 different types (Standard, Regression, Load) but it is possible to add your own types. I need to get all these types.
I believe that this is possible with reflection but that is not my strongest site so I could really use some help here. Please comment if more information is needed.
EDIT:
I've got the following code:
List<string> typeList = new List<string>();
foreach (string type in Test.Types)
{
typeList.Add(type);
}
The above code is not compileable but I hope it illustrates my needs.
foreach (Test t in elm.Tests)
{
string type = t.Type; //It is this type that can be the standards from EA and your own added types
}
// - Output
//Standard
//Regression
//Load
//CustomType1
//CustomType2
Upvotes: 1
Views: 324
Reputation: 13784
There no use for reflection here. These values are stored in the EA database. The "proper" way of querying the API is to use Repository.GetReferencType() like this:
EA.Reference testTypes = Repository.GetReferenceList("Test");
for (short i = 0; i < testTypes.Count; i++)
{
string testType = testTypes.GetAt(i);
}
If you need more then only the name you can query the database directly:
Repository.SQLQuery("select * from t_testtypes")
Upvotes: 3