1. There is a class with a generic method in the class. We're going to call this generic method through reflection.
The namespace is: Transight.HQv4.BLL
Class name is RVCBLL
There are two ways of
A.public List maketest ()
{
return null;
}
B.public list<t> maketest<t> ()
{
return null;
}
2. Reflection, essentially, is the reflection of a namespace string into the object we want.
Example: Assembly bizassembly = Assembly.Load ("Transight.HQv4.BLL");//Reflection namespace var obj = bizassembly.createinstance ("Transigh T.hqv4.bll.rvcbll ", True,
Bindingflags.default, NULL, new Object[]{this. Commonparam}, NULL, NULL)//Create an instance of the class, with an instance of the constructor, equivalent to the Var obj=new rvcbll (this. Commonparam) If you call the normal a method, we can Type test=obj directly. GetType (); MethodInfo Mi1=test. GetMethod ("Maketest"); Mi1. Invoke (Obj,null) 3. So what do we do to call the generic method B?
The above reflection steps do not change, to construct a generic method on the basis of MI1
Type Test=obj. GetType ();
MethodInfo Mi1=test. GetMethod ("Maketest");
MethodInfo mi2 = mi1. MakeGenericMethod (test);
Mi1. Invoke (Obj,null)
C # Invokes a generic method through reflection