您的位置:首页 > 编程语言 > C#

C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名

2009-11-06 10:02 537 查看
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
this.Text = st.GetFrame(0).ToString();

得到代码行,源代码文件名:

StackTrace st = new StackTrace(new StackFrame(true));
Console.WriteLine(" Stack trace for current level: {0}", st.ToString());
StackFrame sf = st.GetFrame(0);
Console.WriteLine(" File: {0}", sf.GetFileName());
Console.WriteLine(" Method: {0}", sf.GetMethod().Name);
Console.WriteLine(" Line Number: {0}", sf.GetFileLineNumber());
Console.WriteLine(" Column Number: {0}", sf.GetFileColumnNumber());

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sphinger/archive/2008/12/21/3568782.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐