简体   繁体   中英

How to find private static methods in static class using reflection?

I have a static class and I want to find its private static methods using typeof(MyStaticClass).GetMethods() but it always shows me the public methods only.

How can I achieve this?

Use the overload of GetMethods that includes a BindingFlags parameter:

var methods = typeof(MyStaticClass)
    .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

(I haven't included BindingFlags.Instance as you've explicitly said it's a static class; to find all methods in any class, include that as well.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM