用Callstack

   1: // First create an instance of the call stack
   2: StackTrace callStack = new StackTrace();
   3:  
   4: // Next select the frame we want...
   5: // 0 : current frame for the current method
   6: // 1 : Frame that called the current method
   7: // 2 : Frame that called the frame that called the current method
   8: // 3 : ...you get the idea!
   9: StackFrame frame = callStack.GetFrame(1);
  10:  
  11: // Using StackFrame.GetMethod(), which returns a 
  12: // MethodBase object, we can obtain detailed 
  13: // information about about a method
  14: MethodBase method = frame.GetMethod();
  15:  
  16: // Get the declaring type and method names 
  17: string declaringType = method.DeclaringType.Name;
  18: string methodName = method.Name;
posted @ 2009-02-03 00:21  new 维生素C.net()  阅读(332)  评论(0编辑  收藏  举报