我有类似的东西
public abstract class Parent
{
public void BeginRequest()
{
var thisType = this.GetType();
var methodInfo = thisType.GetMethod("DoSomething", System.Reflection.BindingFlags.FlattenHierarchy);
Response.Write(methodInfo.Invoke(this, null));
}
}
public class Child : Parent
{
public static string DoSomething() {....}
}
Run Code Online (Sandbox Code Playgroud)
问题是methodInfo总是设置为null.如果我在Parent中创建DoSomething()它可以正常工作.我并不感到惊讶它没有正确接线,但有没有办法可以使它工作?