class GenericMethodReflection
{
public static void PrintTypeParameter<T>()
{
Console.WriteLine (typeof(T));
}
static void Main()
{
Type type = typeof(GenericMethodReflection);
MethodInfo definition = type.GetMethod("PrintTypeParameter");
MethodInfo constructed;
constructed = definition.MakeGenericMethod(typeof(string));
constructed.Invoke(null, null);
}
}
MakeGenericMethod返回一个已构造的泛型方法
在Type中,没有任何方法允许指定类型参数的数量
获取已构造方法后,可以调用,两个参数都是null ,要调用的是静态方法,它不获取任何"普通"的参数。
输出
System.String