C# Generic method and dynamic type problem -


this question has answer here:

i have generic method declared follow :

public void duplicate<entitytype>() { ... } 

so, use need :

myobject.duplicate<int>() 

but here, i'd pass type variable, doesn't work, here how try :

type mytype = anobject.gettype(); myobject.duplicate<mytype>(); 

if can me ?

thank in advance.

you have use reflection, basically:

methodinfo method = typeof(...).getmethod("duplicate"); methodinfo generic = method.makegenericmethod(mytype); generic.invoke(myobject, null); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -