Tuesday 15 September 2015

c# - How to get method name from Action in WinRT -


I'm trying to get the method name from a function in WinRT, where Action.Method is not available yet I have this:

  Public class test 2 {public stable action & lt; Int & gt; Get Deliverate Test; Set; } Private Static String GetMethodName (expression  int & gt; & gt; e) {debug.WriteLine ("e. Body node type {0}", e.b. body type); Method CallExpression MCE = E. Body as MethodCallExpression; If (mce! = Null) {return mce.Method.Name; } Return "error"; } Public static zero print (int x) {Debug.WriteLine ("int {0}", x); } Public static void TestGetMethodName () {TestDelegate = PrintInt; Debug.WriteLine ("PrintInt Method Name {0}", GetMethodName (x = & gt; PrintInt (x)); Debug.WriteLine ("TestDelegate Method Name {0}", GetMethodName (x => Test Delegate (x)); }}   

When I call TestGateMatham (), I get this output:

  e Body. Node type call is the name of the print method. PrintInt E. BODY nodeType Test Delegate is the name ERROR   

The goal is to get the name of the method assigned to test deliate. "GetMethodName (x = & gt; PrintInt (x))" The call is just to prove that I am doing it at least partially correct. How can I tell that "Test Delayed Method Name is a Print?"

itemprop = "text">

The answer is a lot as much as I was making it as easy as it is TestDelegate.GetMethodInfo () . Name. There is no need for my GetMethodName function. I was not using the "system. Reflection" and therefore the rep. Getmothinf was not visible in the Intelligence, and I somehow forgot it in the docs. Code

  public class test 2 {public static action & lt; Int & gt; Get Deliverate Test; Set; } Public static zero print (int x) {Debug.WriteLine ("int {0}", x); } Public static void TestGetMethodName () {TestDelegate = PrintInt; Debug. WrightLine ("TestDelegate Method Name {0}", TestDelegate.GetMethodInfo (.));); }}    

No comments:

Post a Comment