C# 里怎样得到当前执行的函数名,当前代码行,源代码文件名。
发布日期:2021-06-30 19:20:02 浏览次数:2 分类:技术文章

本文共 529 字,大约阅读时间需要 1 分钟。

得到函数名:

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());

转载地址:https://linuxstyle.blog.csdn.net/article/details/3522152 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:web架构设计经验分享
下一篇:C# 特性(Attribute)学习。

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年05月01日 11时46分31秒