怎么获取调用当前函数的代码位置
2016-02-26 09:50
399 查看
用StackTrace 来获取。
本人验证有效
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { 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.ReadLine(); } } }
本人验证有效
相关文章推荐
- Java中遍历Map的几种方法总结
- springmvc 多数据源操作
- JAVA语言常识
- 15个最受欢迎的Python开源框架
- 文科妹子告诉你怎样使用 GitHub!
- 1055. The World's Richest (25)
- Yii安装
- 用python访问URL
- C#简单实现防止多个程序运行的方法
- 设计模式:观察者模式(有利于代码解耦)
- Python的常量
- 多线程编程1 - NSThread
- 工作中接触到的GitHub开源项目
- CMSPRESS-PHP无限级分类2
- C语言 一维数组叠加为二维数组样例
- Spring MVC拦截器配置及其原理分析
- java命令
- Android 开发使用lambda实现< JDK8兼容
- Maven的安装及配置
- java 处理数据库clob类型的字段