C# GetMethod doesn't return a parent method

后端 未结 2 783
一生所求
一生所求 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:28

    You should use one the overloads taking a BindingFlags parameter, and include FlattenHierarchy.

    Specifies that public and protected static members up the hierarchy should be returned. Private static members in inherited classes are not returned. Static members include fields, methods, events, and properties. Nested types are not returned.

    (Edited to remove the point about private static methods, now the question has been changed to make them public.)

提交回复
热议问题