public string GetFullFunName()
        {
            MethodBase mb = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod();
            string name = mb.Name;
            string[] full = mb.DeclaringType.FullName.Split('.');
            return full[full.Length-1] + "." + name;
        }

解决方案 »

  1.   

    public string myNameFunction()
    {
        string str= GetFullFunName();//“myNameFunction”
    }
    获取本方法的方法名字符串。原理:获取调用堆栈中的方法。
      

  2.   

    MethodBase mb = new System.Diagnostics.StackTrace().GetFrame(0).GetMethod();
    会取得现在的方法
    MethodBase mb = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod();
    调用现在的方法的方法
     public string GetFullFunName()
            {
                MethodBase mb = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod();
                string name = mb.Name;
                string[] full = mb.DeclaringType.FullName.Split('.');
                return full[full.Length-1] + "." + name;
            }
    也就是说0的话会永远取得GetFullName()
    改成1的话,看是在哪个方法中呼叫GetFullName(),就会取得该方法名
    A()
    {
      GetFullName();
    }
    会取得A()
    B()
    {
      GetFullName();
    }
    会取得B()