c# - Creating a collection for a base type with methods that will work on all inherited objects? -


I am currently starting a new project and I have participated in some part of a reading block. I am hoping someone can help me and I will do my best to describe this problem.

I have the basics class called "entitybase", this class has about 100 or so legacy classes. There are several ways in EntityBase like load () and save () which are common to all my heritage classes. There are also some constructors that accept an integer or an IDataReader that is used to load the object from the database.

All this is working very well.

class, named EntityCollectionBase which list & lt; EntityBase & gt; Extends up to. I'm trying to write a load function for this but I'm not sure how to proceed, hopefully this code better can clarify my goal:

  public hair Load () {bool result = true; (IDataReader reader = _dbManager.ExectureReaderSProc (this.LoadProcedure, new SqlParameter [] {new SqlParameter ( "@ parentId", _parentID)}) {this.Add (New EntityBase (Reader)); // will not work, EntityBase is ABSTRACT } return result;}  

as you can see, I have nothing needs to load function to operate in the normal way to expand Antitibes, but because EntityBase Abstract I can not instciciate it.

Any thoughts?

Thanks,
Sangeeta

whenever you Make an example of one of many possible classes based on runtime data, respond to a factory:

  public interface Aiititiaifainr {Antitabes Bnaaaintentiti (Aidita Reader reader);}  

you can modify the loading class to accept a:

  private Reedonli IEntityFactory _entityFactory; public loaders (IEntityFactory unit Factory) {_entityFactory = entityFactory; }  

Then load will use the factory method:

  public void Load () {(var reader = _dbManager .ExectureReaderSProc (this.LoadProcedure, new SqlParameter [] {new SqlParameter ( "@ parentId", _parentID)})) Add {(_entityFactory.CreateEntity (Reader)); }}  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -