Pankaj Kaushik
Pankaj Kaushik

Reputation: 137

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?

Upvotes: 2

Views: 1518

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502935

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.)

Upvotes: 4

Related Questions