I have a class that loads data from my database. In this class, I have a function that actually loads the data and returns it to the calling function in the form of a DataTable.
I then iterate through the DataTable and create object of various classes based on each row.
What I would like to do, is change the flow so I can call the function that loads the data in a way that it can determine the type of object that should be created. Here are 2 psuedo calls to show the type of call I would like to make:
List<Teacher> =this.loadData(String sql, Hashtable data, {teachers class});
List<Student> = this.loadData(String sql, Hashtable data, {students class});
Right now the classes Teacher and Student don't extend a common class. However, if it helps, I can make a change like that.
lee
UPDATE:
Thanks to everyone who has given answers so far. It seems none of the solutions would actually improve the code I have or are beyond my programming skills.
I did find this post: Create an instance of a class from a string
In there someone mentions the following technique for creating a class from a string: System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(string className)
However, they also say that the resulting object has to be cast into the actual class. So it makes me wonder if I put the resulting class(before casting) into a List, will doing so automatically cast the object?