Hey all,
I'm currently starting a new project and I've run into a bit of a readblock. I'm hoping someone can help me out and I'll do my best to describe the problem.
I have a base abstract class called "EntityBase". From this class there are around 100 or so inherited classes. EntityBase has a number of methods such as Load() and Save() that are common to all my inherited classes. It also has a couple of constructors that accept either an integer or an IDataReader which are used to load the object from the database.
That's all working quite well.
Enter my new base class, named EntityCollectionBase which extends List<EntityBase>. I'm trying to write a Load function for it but I'm not sure how to proceed. Hopefully this bit of code can better illustrate my goal:
public bool Load()
{
bool result = true;
using (IDataReader reader = _dbManager.ExectureReaderSProc(this.LoadProcedure, new SqlParameter[] { new SqlParameter("@parentId", _parentID) }))
{
this.Add(new EntityBase(reader)); // WON'T WORK, EntityBase IS ABSTRACT
}
return result;
}
As you can see, I need the Load function to work in a generic manner to handle anything extending EntityBase, but because EntityBase is abstract, I cannot instanciate it.
Any ideas?
Thanks,
Sonny