映射获取调用方法的方法名称c#

using System.Diagnostics;
using System.Reflection;

StackTrace ss = new StackTrace(true);
    string t =ss.GetFrame(2).GetMethod().DeclaringType.ToString()+"."+ss.GetFrame(2).GetMethod().Name;
       return t;

获取2级调用的方法名称,GetFrame(index),index的值讲影响获取的层级方法。

StackTrace ss = new StackTrace(true);
            string t = ss.GetFrame(2).GetMethod().DeclaringType.ToString();
            int index = t.LastIndexOf(".");
            t = t.Remove(index);

获取调用方法的空间名称。t返回的是类名称,包含空间。

原文地址:https://www.cnblogs.com/jinyuttt/p/2055710.html