Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Dave_Bullet on April 08, 2008, 07:42:17 am
-
I know Repository.GetElementsByQuery returns an EA.Collection - but what types of objects are returned and how can I access their properties?
I'm pretty rusty at programming and learning C#. I can't for the life of me figure out how to inspect the returned collection to find the underlying object types returned.
The collection contains a count of 5 after the method call and objecttype = otCollection. What I want to know is what type of objects are contained in the collection so I can cast and use them appropriately.
Thanks,
David.
-
I suspect without proof that it returns a collection of Element objects. With each item you can inspect the Type property to determine what you got.
David
-
Hi David,
Thanks for your reply. I tried casting one of the objects in the collection to an Element via adding a watch in Visual Studio during debuggin and Visual Studio barfed, ie:
result = rep.GetElementsByQuery("Simple", "<search term>");
(Element)(result.GetAt(0));
I'll try running in code incase it is a syntax issue with my casting or a runtime issue calling GetAt() within the watch window.
Cheers,
David.
-
Remember to call GetAt with a short integer parameter.
-
ObjectType returns the type of the object. Search the help.
-
And remember that the object type of a (say) use case is element rather than use case. You need to use the type property to break it down to the specific type.
I trip over this each time I've been away from these collections for a few months.
David
-
This works:
Dim oQueryElements As EA.Collection
Dim oElement As EA.Element
Set oQueryElements = Repository.GetElementsByQuery("Simple", "whatever")
For Each oElement In oQueryElements
msgbox "oElement.Name = " & oElement.Name
Next oElement