我使用Visual Studio 2010,.NET 3.5和PostSharp 3.1.33。當我執行這個代碼如何在原來的方法使用PostSharp時獲取方法的名稱?
[MyInterceptorAspect]
public void Send(string msg)
{
Console.WriteLine(MethodBase.GetCurrentMethod().Name);
}
它打印<Send>z__OriginalMethod
,但我希望它僅打印Send
。它有可能嗎? (注意:MyInterceptorAspect擴展了MethodInterceptionAspect,它的工作原理完美無缺,具體實現對於這個問題並不重要)
這是有幫助嗎? http://stackoverflow.com/questions/2652460/c-sharp-how-to-get-the-name-of-the-current-method-from-code –
@ Ron.B.I TNX,那種。我不得不使用'新的StackTrace()。GetFrame(4).GetMethod()。名稱',這讓我感覺有點不舒服,因爲這個魔術數字。幀1,幀2和幀3指的是一些PostSharp的方法。 –