表达式树获取函数命名

https://www.tuicool.com/articles/qIZVBre

定义一个类,下面通过表达式树从类获得函数命名

class Foo
    {
        public void KzcSevfio()
        {
        }
    }
static void Main(string[] args)
        {
            GetMethodName<Foo>(foo => foo.KzcSevfio());
        }

        private static void GetMethodName<T>(Expression<Action<T>> action) where T : class
        {
            if (action.Body is MethodCallExpression expression)
            {
                Console.WriteLine(expression.Method.Name);
            }
        }
原文地址:https://www.cnblogs.com/atuo/p/9198174.html