学习笔记(二)C#获取当前正在执行的代码的命名空间、类、方法的名称

来源:互联网 发布:java https post请求 编辑:程序博客网 时间:2024/06/05 16:45

静态:

命名空间+类:System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName 

命名空间:System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace

类:System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name

方法:new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name


非静态:

命名空间:this.GetType().ToString()

类:this.GetType().Name

方法:new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name


0 0
原创粉丝点击