3
System.Reflection
是否有一個方法獲取調用另一個方法的方法的名稱空間?我目前擁有的是:獲取調用方法的名稱空間和程序集
var stackTrace = new System.Diagnostics.StackTrace();
MethodBase method = stackTrace.GetFrame(1).GetMethod();
string namespace = method.DeclaringType.Namespace;
Assembly assembly = method.DeclaringType.Assembly;
複製 - http://stackoverflow.com/questions/615940/retrieving-the-calling-method-name-from-within-a-method-c – eyossi
當心在Release配置優化它可以改變調用堆棧。 – ashes999
您可以使用[System.Runtime.CompilerServices.MethodImpl( System.Runtime.CompilerServices.MethodImplOptions.NoInlining)],以便在發佈時不會內聯該方法 – eyossi