在.NET中怎样取得代码行数
文章目的
介绍在.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 class that corresponds to a frame above the current stack frame, optionally capturing source information.">StackFrame class that corresponds to a frame above the current stack frame, optionally capturing source information."> StackFrame class that corresponds to a frame above the current stack frame, optionally capturing source information.">初始化与当前堆栈帧之上的帧相应的 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 + ")");
}
在.NET中怎样取得代码行数的更多相关文章
- Python计算一个项目中含有的代码行数
最近想要知道以前做过的project有多少行代码,因为文件太多,直接手工数效率太低,于是编写一个python程序用来计算一个project有多少代码行. 首先,在一个项目中,有很多子文件夹,子文件夹中 ...
- python3 计算文件夹中所有py文件里面代码行数,注释行数,空行数
import os,re #代码所在位置 FILE_PATH = './' def analyze_code(codefilesource): ''' 打开一个py文件统计其中的代码行数,包括空格和注 ...
- 使用 cloc 统计代码行数
可能大家都知道用 `wc -l` 命令进行代码行数统计,但是它会将代码中的注释.空行所占用的文本行都统计在内.如果想查看一个 tar 包或一个项目目录中“实际”的代码行数并且不愿意自己去写一个脚本来做 ...
- 【原】Mac下统计任意文件夹中代码行数的工具——cloc
这里介绍一个Mac系统统计代码行数的工具cloc. 1.首先,安装homebrew,已安装的请跳过. 打开终端工具Terminal,输入下列命令.过程中会让你按RETURN键以及输入mac桌面密码,按 ...
- 【未解决】对于使用Windows的IDEA进行编译的文件,但无法在Linux系统中统计代码行数的疑问
在我学习使用Windows的IDEA的过程中,将代码文件转移到Linux虚拟机当中,但无法在Linux系统中统计代码行数. 注意:拷贝进虚拟机的文件均能编译运行. 具体过程如下: root@yogil ...
- 使用vs的查找功能,简单大概的统计vs中的代码行数
VS强大的查找功能,可以使用正则表达式来进行查找,这里统计代码行数的原理就是: 在所有指定文件中进行搜索,统计匹配的文本行数. 但是匹配的行需要满足:非注释.非空等特殊非代码行. 使用Ctrl+Shi ...
- 【原】Mac下统计任意文件夹中代码行数的工
[链接][原]Mac下统计任意文件夹中代码行数的工http://www.cnblogs.com/wengzilin/p/4580646.html
- 关于Servo项目中Rust代码行数的数据来源
我两个月之前的一篇博客<为什么我说Rust是靠谱的编程语言>(下面简称原文),在当中"6. 两个半大型成功案例"一节.我以前写道: Servo: 下一代浏览器渲染引擎( ...
- vs2010 vs2013等vs中如何统计整个项目的代码行数
在一个大工程中有很多的源文件和头文件,我如何快速统计总行数? ------解决方案--------------------b*[^:b#/]+.*$^b*[^:b#/]+.*$ ctrl + shif ...
随机推荐
- 树状数组 - BZOJ 1103 [POI2007]大都市
bzoj 1103 [POI2007]大都市 描述 在经济全球化浪潮的影响下,习惯于漫步在清晨的乡间小路的邮递员 Blue Mary也开始骑着摩托车传递邮件了.不过,她经常回忆起以前在乡间漫步的情景. ...
- 初学-BeautifulSoup爬取豆瓣页面
# -*- coding: utf-8 -*-import osimport urllibimport urllib2from bs4 import BeautifulSoup headers = { ...
- 为Anaconda添加新的源
为Anaconda添加新的源 在cmd中输入以下内容即可, 清华的源,速度非常快 conda config --add channels https://mirrors.tuna.tsinghua.e ...
- Leetcode with Python
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...
- HLG2179 组合(dfs水水更健康)
组合 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 57(38 users) Total Accepted: 43(36 users) ...
- 九度oj 1004
题目1004:Median 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17536 解决:4860 题目描述: Given an incre ...
- fish shell安装和配置
sudo apt-get install fish whereis fish chsh -s /usr/bin/fish 重启:
- ——CentOS 7 安装SQL Server2019
环境准备 不废话,先把研究环境搭建起来.由于某些原因(晚点再说),本系列首先使用CentOS 7作为操作系统.官方指引中支持的Linux平台及文件系统中并没有指出CentOS,但是作为与Red Ha ...
- 通过rabbitmqadmin管理rabbitmq
# 安装rabbitmq $ sudo apt install rabbitmq-server # 下载rabbitmqadmin管理工具 sudo rabbitmq-plugins enable r ...
- 深入浅出mysql全文随笔
进入mysql :mysql -uroot -p 1.DDL(Data Definition Languages)语句:数据定义语言 2.DML(Data Manipulation Language) ...