Asp.net .net(C#) 獲取當前命名空間,類名,方法名的方法


public  static  string  GetMethodInfo()
{
     string  str =  ""
     //取得當前方法命名空間
     str +=  "命名空間名:" +System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "\n" ;
     //取得當前方法類全名 包括命名空間
     str +=  "命名空間+類名:" +System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName +  "\n" ;
     //獲得當前類名
     str +=  "類名:" +System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name+  "\n" ;
     //取得當前方法名
     str +=  "方法名:" +System.Reflection.MethodBase.GetCurrentMethod().Name +  "\n" ;
     str +=  "\n" ;    
     StackTrace ss =  new  StackTrace( true );
     MethodBase mb = ss.GetFrame(1).GetMethod();
     //取得父方法命名空間
     str += mb.DeclaringType.Namespace +  "\n" ;
     //取得父方法類名
     str += mb.DeclaringType.Name +  "\n" ;
     //取得父方法類全名
     str += mb.DeclaringType.FullName +  "\n" ;
     //取得父方法名
     str += mb.Name +  "\n" ;
     return  str;
}
public  static  void  Main()
{
     Console.WriteLine(GetMethodInfo());
     Console.ReadKey();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM