码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2014-12-30 16:50:52      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

 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 

 

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

标签:

原文地址:http://www.cnblogs.com/Belong/p/4193925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!