怎样知道是哪个方法调用了我?
比如有方法A,当B方法调用A时,怎么才能在A里知道是B在调用?
[解决办法]
在B里可以通过反射,在堆栈里查找
System.Reflection.MethodInfo mi = (System.Reflection.MethodInfo) (new StackTrace().GetFrame(1).GetMethod());
if(mi.Name=="A")
//A调用的
[解决办法]
static void A()
{
StackFrame sf = new StackTrace().GetFrame(1);
Console.WriteLine(sf.GetMethod().Name);
}