WinRT의 작업에서 메서드 이름을 가져 오려고하는데, 여기서 Action.Method를 사용할 수 없습니다. 지금까지이있다 :WinRT의 작업에서 메서드 이름을 가져 오는 방법
public class Test2
{
public static Action<int> TestDelegate { get; set; }
private static string GetMethodName(Expression<Action<int>> e)
{
Debug.WriteLine("e.Body.NodeType is {0}", e.Body.NodeType);
MethodCallExpression mce = e.Body as MethodCallExpression;
if (mce != null)
{
return mce.Method.Name;
}
return "ERROR";
}
public static void PrintInt(int x)
{
Debug.WriteLine("int {0}", x);
}
public static void TestGetMethodName()
{
TestDelegate = PrintInt;
Debug.WriteLine("PrintInt method name is {0}", GetMethodName(x => PrintInt(x)));
Debug.WriteLine("TestDelegate method name is {0}", GetMethodName(x => TestDelegate(x)));
}
}
내가 TestGetMethodName를 호출 할 때() 나는이 출력 얻을 :
이e.Body.NodeType is Call
PrintInt method name is PrintInt
e.Body.NodeType is Invoke
TestDelegate method name is ERROR
목표는 TestDelegate에 할당 된 메소드의 이름을 취득하는 것입니다. "GetMethodName (x => PrintInt (x))"호출은 내가 적어도 부분적으로 올바르게하고 있음을 증명하기 위해서만 존재합니다. 어떻게하면 "TestDelegate 메서드 이름이 PrintInt"인지 알 수 있습니까?
감사합니다,하지만 Delegate.Method는 WinRT에 존재하지 않습니다
작업 코드입니다. 하지만 코드를 가지고 놀면서 나는 처음부터 필요한 모든 Delegate.GetMethodInfo()를 발견했습니다. – mkelly4ca