C#获取当前运行的源代码的文件名和当前源代码的行数的方法

 1         /// <summary>
 2         /// 取得当前源码的哪一行
 3         /// </summary>
 4         /// <returns></returns>
 5         public static int GetLineNum()
 6         {
 7             System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
 8             return st.GetFrame(0).GetFileLineNumber();
 9         }
10 
11         /// <summary>
12         /// 取当前源码的源文件名
13         /// </summary>
14         /// <returns></returns>
15         public static string GetCurSourceFileName()
16         {
17             System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
18 
19             return st.GetFrame(0).GetFileName();
20         }
21 
原文地址:https://www.cnblogs.com/Belong/p/4193925.html