I have a generic class with the generic parameter constrained to entity types. I need a way to get a new collection of the given type. That is, I need to implement this method...
public class MyClass<TEntity> where TEntity : CommonEntityBase
{
// If TEntity is ProductEntity, return a new ProductCollection
// If TEntity is CustomerEntity, return a new CustomerCollection
// etc
protected IEntityCollection GetTEntityCollection()
{
...
}
}
Here's the best implementation I have so far. Is there a way to do it without using reflection and creating an entity instance like I have done?
public class MyClass<TEntity> where TEntity : CommonEntityBase
{
protected IEntityCollection GetTEntityCollection()
{
IEntity entity = Activator.CreateInstance(genericEntityType) as TEntity;
EntityType entityType = (EntityType)Enum.ToObject(typeof(EntityType), entity.LLBLGenProEntityTypeValue);
return GeneralEntityCollectionFactory.Create(entityType);
}
}
I'm using LLBLGen Pro 2.5 with the SelfServicing, two class scenario.