在.NET中如何取得代码行数
来源:互联网 发布:软件小公司利润率 编辑:程序博客网 时间:2024/05/16 10:23
文章目的
介绍在.NET中取得代码行数的方法
代码
[STAThread]static void Main(string[] args){ ReportError("Yay!");}static private void ReportError(string Message){ StackFrame CallStack = new StackFrame(1, true); Console.Write("Error: " + Message + ", File: " + CallStack.GetFileName() + ", Line: " + CallStack.GetFileLineNumber());}
StackFrame(Int32, Boolean) 初始化与当前堆栈帧之上的帧对应的 StackFrame 类的新实例,可以选择捕获源信息。
GetFileName :获取包含所执行代码的文件名。 该信息通常从可执行文件的调试符号中提取。
GetMethod :获取在其中执行帧的方法。
GetFileLineNumber :获取文件中包含所执行代码的行号。 该信息通常从可执行文件的调试符号中提取。
利用Exception(例外)的StackTrace类
try{ throw new Exception();}catch (Exception ex){ // Get stack trace for the exception with source file information var st = new StackTrace(ex, true); // Get the top stack frame var frame = st.GetFrame(0); // Get the line number from the stack frame var line = frame.GetFileLineNumber();}
.NET4.5 新方法
static void SomeMethodSomewhere(){ ShowMessage("Boo");}...static void ShowMessage(string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null){ MessageBox.Show(message + " at line " + lineNumber + " (" + caller + ")");}
1 0
- 在.NET中如何取得代码行数
- 如何在代码中取得一个特点type的关节
- 如何在Eclipse统计代码行数
- 如何在Eclipse统计代码行数
- 如何在Windows下统计代码行数
- .NET-获取项目中代码行数
- 取得Gridview中当前行数
- asp.net中如何取得系统参数
- 如何在MyEclipse中显示行数
- 如何在MyEclipse Eclipse中显示行数
- 如何在MyEclipse中显示行数
- 如何在MyEclipse Eclipse中显示行数
- 如何在vb.net中取得两时间的毫秒差
- 如何在vb.net中取得两时间的毫秒差
- 如何在PB中取得硬件识别码
- 如何在PB中取得全球识别码
- 如何在Spring中取得Request对象
- 如何统计代码行数
- Android实现程序前后台切换效果
- JVM调优总结(十)——调优方法
- Asp.Net MVC4.0 官方教程 入门指南之二--添加一个控制器
- Apple Swift 编程语言简单入门(上)
- MyEclipse参加jquery.js文件missing semicolon的错误
- 在.NET中如何取得代码行数
- 自定义函数入门
- 个人对数据结构的理解和总结
- spring mvc使用@InitBinder 标签对表单数据绑定
- 如何手动的干净的删除linux上的ORACLE数据库
- Android HttpURLConnection用法详解
- 润乾——报表级填报属性
- ubuntu命令安装内核源码及升级内核源码
- Cocos2dx3.1 获取当前系统时间