c# - Getting method name from an Action delegate -


i'm trying method name passed action delegate. have:

private static void doaction(params action<group>[] actions) {     foreach (action<group> action in actions)     {         console.writeline(action.method.name);     } } 

and in main, how gets called:

doaction(y => y.dobar(), z => z.dofoo()); 

after execution of doaction() method hoping see "dofoo" , "dobar" on screen, instead see <main>b__0 , <main>b__1. wondering if there's way actual name of target method action delegate? appreciated.

you can change input type expression , see if expression method call:

private static void doaction(params expression<action<group>>[] actions) {     foreach (var exp in actions)     {         var method = exp.body methodcallexpression;         if(method != null)             console.writeline(method.method.name);          // similar method properties         var member = exp.body memberexpression;         if (member != null)             console.writeline(member.member);          // execute action         action<group> act = exp.compile();          group g = new group();  // create group act on         act(g);  // perform action      }  } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -