1
我有这些类:调用泛型方法的类型
public static class A{
...
public C Run<T>(string something)
{
...
}
}
public static class B{
...
public void Exec<T>(Type type)
{
MethodInfo method = typeof(A).GetMethod("Run");
MethodInfo generic = method.MakeGenericMethod(type);
var result = generic.Invoke(null, new object[] { "just a string" });
// bad call in next line
result.DoSomething();
}
}
public class C{
...
public void DoSomething(){}
}
如何转换结果到呼叫DoSomething的方法类型?而使用类型变量调用泛型方法有多简单?
好。使用'dynamic'是唯一的方法 –