function main()
{
Hello();
}
function Hello()
{
// How do you find out the caller function is 'main'?
}
Run Code Online (Sandbox Code Playgroud)
有没有办法找出调用堆栈?
登录C#时,如何学习调用当前方法的方法的名称?我知道所有这些System.Reflection.MethodBase.GetCurrentMethod(),但我想在堆栈跟踪中向下迈出一步.我考虑过解析堆栈跟踪,但我希望找到一种更清晰,更明确的方法,比如Assembly.GetCallingAssembly()方法.
可能重复:
如何找到调用当前方法的方法?
嗨,我怎样才能从方法中确定方法的调用者?例如:
SomeNamespace.SomeClass.SomeMethod() {
OtherClass();
}
OtherClass() {
// Here I would like to able to know that the caller is SomeNamespace.SomeClass.SomeMethod
}
Run Code Online (Sandbox Code Playgroud)
谢谢