zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C#获取当前正在执行的代码的命名空间、类、方法的名称

c#方法执行代码 获取 空间 当前 命名
2023-09-14 09:10:47 时间

转载 https://blog.csdn.net/huaxiyuan/article/details/52677889
静态:

命名空间+类: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