class A
{
public static void M<T>() { ... }
}
...
Type type = GetSomeType();
Run Code Online (Sandbox Code Playgroud)
然后我需要在A.M<T>()哪里打电话type == typeof(T).
反射?
是的,你需要反思.例如:
var method = typeof(A).GetMethod("M");
var generic = method.MakeGenericMethod(type);
generic.Invoke(null, null);
Run Code Online (Sandbox Code Playgroud)