【发布时间】:2023-04-05 23:13:01
【问题描述】:
假设我知道Type 变量的值和静态方法的名称,我如何从Type 调用静态方法?
public class FooClass {
public static FooMethod() {
//do something
}
}
public class BarClass {
public void BarMethod(Type t) {
FooClass.FooMethod() //works fine
if (t is FooClass) {
t.FooMethod(); //should call FooClass.FooMethod(); compile error
}
}
}
因此,给定一个Type t,目标是在属于Type t 的类上调用FooMethod()。基本上我需要反转typeof() 运算符。
【问题讨论】:
标签: c#