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

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -