Generics

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 14-Jul-2005 21:08:16   

Hi,

If the next verison of LLBLGen has code like this...

 EntityCollection<CustomerEntity> c = new EntityCollection<CustomerEntity>();

How would I create a collection if I didn't know the type until runtime?

Cheers,

I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 14-Jul-2005 21:47:23   

Good point! I'll make sure that's possible. Sometimes new features like generics can make you overlook the obvious things which also have to be possible.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 14-Jul-2005 21:51:05   

On second thought, you could of course do: EntityCollection<IEntity> c = new EntityCollection<IEntity>();

Though if that doesn't work as planned, it will be possible in another way so you can set the type at runtime so you can use the entitycollection as a generic container.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 15-Jul-2005 00:09:06   

ok, glad you're considering this.

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 16-Jul-2005 20:14:03   
 EntityCollection<IEntity> c = new EntityCollection<IEntity>();

I don't see how this could work. In the current version of LLBLGen you have to supply a factory method so that, I believe, the collection knows how to create an instance of the objects it contains.

With..

class EntityCollection<K>

..then you can, of course, just call...

new K();

But you can't instantiate an instance of an interface.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 16-Jul-2005 20:32:44   

True, but I can add a method to the interface which produces the factory wink simple_smile

In fact, that's how I'll do it, not new K();, as the creation of a new instance is done in the fetch core, not in the entity collection itself (only in databinding scenarios).

Frans Bouma | Lead developer LLBLGen Pro