c# - Get generic method definition of implemented generic class -


public class target3<t,t2> {     t gettgenerictest(t2 obj); } 

in above code, gettgenerictest not genericmethod, makegenericmethod can of course not used. so, when have methodinfo belonging object of iinterfacetarget3<string,int>, can work it's non-defined version? can't use makegenerictype because have no way link current methodinfo non-defined one.

(pseudo code keep short)

list<methodinfo> undefs = new list<methodinfo>(); void x() {     type t = typeof(target3<,>);     methodinfo undefmi = t.getmethod("gettgenerictest");     undefs.add(undefmi); }  void y() {     var obj = new target3<string,int>();     methodinfo defmi = obj.gettype().getmethod("gettgenerictest");      //how this?     methodinfo undefmi = undefs.firstordefault(u=> defmi.undefinedversion() == u); } 

if have non-generic method in generic class, not easy "convert" non-generic method in generic class definition. trick:

methodinfo mi1 = typeof(target3<string, int>).getmethod("gettgenerictest"); methodinfo mi2 = mi1.declaringtype.getgenerictypedefinition().getmethod(     mi.name,     (mi.isstatic ? bindingflags.static : bindingflags.instance) |     (mi.ispublic ? bindingflags.public : bindingflags.nonpublic),     null,     mi.getparameters().select(p => p.parametertype).toarray(),     null); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -