小编Sun*_*aul的帖子

我们如何在 C# 中获取异步方法名称

我想通过使用反射等来获取此方法的名称...我使用了很多东西,但我累了,请帮助我。如果该功能是同步的,那么下面的代码将正常工作。请仔细阅读下面的代码,这将清除我的问题。

// 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)

c# asp.net asp.net-mvc c#-3.0 c#-4.0

2
推荐指数
1
解决办法
2906
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

c# ×1

c#-3.0 ×1

c#-4.0 ×1