Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the MethodInfo of static method of a static class

I'm trying to get the MethodInfo of a static method in a static class. When running the following line, I only get the basic 4 methods, ToString, Equals, GetHashCode and GetType:

MethodInfo[] methodInfos = typeof(Program).GetMethods();

How can I get the other methods that are implemented in this class?

like image 494
Urik Avatar asked Jun 28 '12 14:06

Urik


People also ask

Can we inherit the static method?

Static methods take all the data from parameters and compute something from those parameters, with no reference to variables. We can inherit static methods in Java.

Do static methods return values?

A static method can only use and call other static methods or static data members. It is usually used to operate on input arguments (which can always accept), perform calculation and return value.

Do static method take up memory?

Static data and static methods do not take up memory in individual instances.


2 Answers

Try this way:

MethodInfo[] methodInfos = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.Public);
like image 185
Volodymyr Dombrovskyi Avatar answered Oct 11 '22 04:10

Volodymyr Dombrovskyi


var methods = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
like image 38
Matthew Abbott Avatar answered Oct 11 '22 03:10

Matthew Abbott