相关疑难解决方法(0)

如何找到调用当前方法的方法?

登录C#时,如何学习调用当前方法的方法的名称?我知道所有这些System.Reflection.MethodBase.GetCurrentMethod(),但我想在堆栈跟踪中向下迈出一步.我考虑过解析堆栈跟踪,但我希望找到一种更清晰,更明确的方法,比如Assembly.GetCallingAssembly()方法.

.net c# logging system.diagnostics stack-trace

465
推荐指数
11
解决办法
21万
查看次数

回答"哪种方法叫我?" 在.NET的运行时?或者代码可以读取CallStack数据吗?

假设有methodA(),methodB()和methodC().

并且在运行时调用methodC().

有可能知道从哪个方法调用methodC()?

我在想是否可以在运行时读取CallStack以进行某些检查?如果是,我认为这应该不是什么大问题.

有任何想法吗?

谢谢!

reflection methods callstack runtime call

2
推荐指数
1
解决办法
287
查看次数

如何在运行时从方法中查找调用方法的方法名称?

如何在运行时从方法中找到调用方法的方法名称?

例如:

Class A
{
    M1()
    {
        B.M2();
    }
}

class B
{
    public static M2()
    {
        // I need some code here to find out the name of the method that
        // called this method, preferably the name of the declared type
        // of the calling method also.
    }
}
Run Code Online (Sandbox Code Playgroud)

.net reflection

0
推荐指数
1
解决办法
1422
查看次数