打印在C#源文件名和行号 [英] Print the source filename and linenumber in C#

查看:568
本文介绍了打印在C#源文件名和行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法来检索C#code当前的源文件名和行号,并打印在控制台输出值?像订单文件用C?

Is there any way to retrieve the current source filename and linenumber in C# code and print that value in the console output? Like LINE and FILE in C?

请指教。

非常感谢

推荐答案

这个答案已经过时了!见@taras'以获取更多最新信息的答案。

没有不变:(

你可以做很多丑陋的:

string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); 
int currentLine = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(); 

只能当PDB文件是可用的。

Works only when PDB files are available.

这篇关于打印在C#源文件名和行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆