Bogdan Verbenets Bogdan Verbenets - 4 years ago 216
C# Question

get methodinfo from a method reference C#

We can use a C#

keyword when we want to get Type instance for specified type. But what can I use if I want to get
of a method by it's reference?

For example I have a simple console app. It contains
method. I want to get
by using something like
. I have this problem because the method names might change, so I cannot just use
Type.GetMethodInfo(string MethodName)
for that.

I have about 10 000 methods for which I would like to get
, so adding any custom attributes or anything else to my methods is not a solution.

Answer Source

Slight adaptation of a previously posted answer, but this blog post seems to achieve what you're asking for;

Sample usage would be as follows;

var methodInfo = SymbolExtensions.GetMethodInfo(() => Program.Main());

Original answer was to this question;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download