4
通常情况下,我在反思访问的方法是这样的:如何使用反射访问显式实现的方法?
class Foo
{
public void M() {
var m = this.GetType().GetMethod ("M");
m.Invoke(this, new object[] {}); // notice the pun
}
}
然而,当M是一个明确的执行失败:
class Foo : SomeBase
{
void SomeBase.M() {
var m = this.GetType().GetMethod ("M");
m.Invoke(this, new object[] {}); // fails as m is null
}
}
如何访问使用反射的明确实现的方法?
在这种情况下,'M '是私人的。你应该使用'BindingFlags'枚举。 – Steven 2010-09-06 10:08:38