【发布时间】:2010-11-18 06:39:33
【问题描述】:
如何在运行时从方法中找到调用方法的方法名?
例如:
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.
}
}
【问题讨论】:
-
认为您需要实现这样的目标通常是应用程序设计存在缺陷的好兆头。最好回顾一下设计,看看是否可以先解决这个问题。但是,在这种情况下,这并不总是严格正确的。为什么需要这样做?
-
@Jon:我自己从来没有做过,虽然我已经接近了几次。当试图理解刚刚落在您盘子上的热气腾腾的一堆时,这可能是一种有用的技术。
-
调试器知道怎么做——为什么其他人需要知道怎么做?
标签: .net reflection