Get current method name from async function?

后端 未结 8 1293
我在风中等你
我在风中等你 2020-12-04 01:43

Is there anyway to get the current method name from inside an async function?

I\'ve tried:

System.Reflection.MethodInfo.GetCurrentMethod();
         


        
8条回答
  •  孤街浪徒
    2020-12-04 01:55

    This method works from async method call as well as from normal method. (C#5)

    /// 
    ///     Returns Current method name
    /// 
    /// callers method name
    public string GetCurrentMethod([CallerMemberName] string callerName = "")
    {
        return callerName;
    }
    

提交回复
热议问题