Book a Demo

Author Topic: Modeling and generating collections for VB  (Read 3315 times)

Peter Daniels

  • Guest
Modeling and generating collections for VB
« on: May 20, 2002, 12:43:16 pm »
How do I model a collection of objects in EA that will be used to gen VB code?  I would like to end up with a custom collection class.

Example: I have a class foo and want to have another class, foos, that is a collection of foo objects.  I want the foos class to have a private member var that is a generic VB collection.  I also want to create my own implementations of Item(), Remove(), Add(), etc.  How can I use EA to model this and generate the code correctly?

Thx a mil,

-Peter

Steve Jackson

  • Guest
Re: Modeling and generating collections for VB
« Reply #1 on: May 20, 2002, 12:58:31 pm »
Here's how I did it:

To properly implement collections, your VB collection class needs to implement the IEnumerable interface.  This allows foreach/next processing.  You can find documentation about this in MSDN.  

Basically, from your custom collection class (Foos) you instrument one method, GetEnumerator(this) and house your collection of Foo objects in a construct like an ArrayList (.NET)  Don't forget to reference the fact that Foos implements IEnumerable.

Create another class FooEnumerator:IEnumerator(Foos) with methods Reset, MoveNext, Current and IEnumerator.Current.  

In EA, create a Class (Foos) and reflect the method GetEnumerator(this).  Create another class (FooEnumerator) and reflect the methods Reset, MoveNext, Current and IEnumerator.Curent.  Stereotype it as an Interface.

That should be all you need.

Matt

  • EA User
  • **
  • Posts: 96
  • Karma: +0/-0
    • View Profile
    • Solutions Reality
Re: Modeling and generating collections for VB
« Reply #2 on: May 21, 2002, 01:33:23 am »
Steve, would you have an example model of this without too much private detail to show how you did it?