This question already has an answer here:
How to call generic method by class name as a type?
Example:
public class WorkItem
{
public T GetById<T>(int id) where T : Dto
{
...
}
}
It is easy to call: workItem.GetById(1);
But I need to call this method with known name "CoolDto", is it possible?
I was trying
var t = assembly.GetType(Namespace + dtoName);
workItem<t>.GetById(1);
But it doesn't work. Please advice me.
Aucun commentaire:
Enregistrer un commentaire