Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get the current class' name in a static method?
  2. new StackFrame().GetMethod().DeclaringType
  3.        
  4. MethodBase.GetCurrentMethod().DeclaringType
  5.        
  6. new StackTrace(true).GetFrame(<frame index>).GetMethod() //e.g. <frame index> = 0
  7.        
  8. string className = typeof(MyClass).Name;
  9.        
  10. private MyStaticClass
  11. {
  12.     // ...
  13. }
  14.  
  15.  
  16. public static Type MyStaticMethiod()
  17. {
  18.      return new MyStaticClass().GetType();
  19. }