C# GetMethod doesn't return a parent method

后端 未结 2 797
一生所求
一生所求 2020-12-20 12:27

I have the following class tree:

public class A
{
    public static object GetMe(SomeOtherClass something)
    {
        return something.Foo();
    }
}

pub         


        
2条回答
  •  独厮守ぢ
    2020-12-20 13:23

    You need to pass BindingFlags.FlattenHierarchy flag to GetMethod in order to search up the hierarchy:

    typeof(C).GetMethod("GetMe", BindingFlags.FlattenHierarchy, null, new Type[] { typeof(SomeOtherClass) }, null)).Invoke(null, parameter));
    

提交回复
热议问题