Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the function name from function pointer in C#?

I have a function which takes a function pointer

like

public void myfunc<a,b>(Func<a,b> functionpointer)
{
  String functionname;
  // Do some magic to get functionpointers name and set it to functionname
 }

Is it possible to get the function's name without running it?

I know that you can get the function name of the currently running function, but how do you get the name of a function that you're going to call?

Forgive me if such a question might have been posted before, i can't find a solution for it in C#

like image 528
Brijesh Bharadwaj Avatar asked Nov 28 '12 07:11

Brijesh Bharadwaj


1 Answers

You can use MemberInfo.Name Property

string functionname = functionpointer.Method.Name;
like image 86
Habib Avatar answered Oct 13 '22 00:10

Habib