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
Post a Comment