我想通过使用反射等来获取此方法的名称...我使用了很多东西,但我累了,请帮助我。如果该功能是同步的,那么下面的代码将正常工作。请仔细阅读下面的代码,这将清除我的问题。
// this will work fine
public void Test()
{
// This GetCurrentMethod() will you the name of current method
string CurrentMethodName = GetCurrentMethod();
// output will be CurrentMethodName = Test
}
// this will not work
public async Task<int> GETNumber(long ID)
{
// This GetCurrentMethod() will you the name of current method if the method is sync or not async
string CurrentMethodName = GetCurrentMethod();
return await Task.Run(() => { return 20; });
}
Run Code Online (Sandbox Code Playgroud)
此方法为我提供非异步方法的名称。但我如何获得上面的方法名称
> [MethodImpl(MethodImplOptions.NoInlining)]
> public …Run Code Online (Sandbox Code Playgroud)