In my project (.NET 3.5), I got a lot of DAO: (for each object)
public class ProductDAO : AbstractDAO<Product> {...}
I need to create a function that gets the name DAO or the name of its entity (whatever you think is better) and run the function "getAll ()" DAO. As this code does for only one object:
ProductDAO dao = new ProductDAO(); dao.getAll();
I'm new to C #, how can I do this with reflection?
The socket is as follows:
String entityName = "Product"; AbstractDAO<?> dao = new AbstractDAO<entityName>() dao.getAll();
Edit
One detail I forgot is how getAll () returns:
IList<Product> products = productDao.getAll();
Therefore, I will also need to use reflection in the list. How?
Decision
Type daoType = typeof(AbstractDAO<>).Assembly.GetType("Entities.ProductDAO"); Object dao = Activator.CreateInstance(daoType); object list = dao.GetType().GetMethod("getAll").Invoke(dao, null);
source share