提问人:Abdullah Rana 提问时间:6/15/2023 最后编辑:Theodor ZouliasAbdullah Rana 更新时间:6/16/2023 访问量:58
如何从调用扩展方法的扩展方法中获取异步方法名称?
How to get the asynchronous method name in the extension method from where the extension method is called?
问:
如何从调用扩展方法的扩展方法中获取异步方法名称?
我有一些这样的异步方法:
async Task ProcessUnchangedElementsAsync(ob1, ob2, ob3)
{
await Task.Delay(500);
}
以及这些异步方法的扩展方法,如下所示:
public static async Task Log(this Task task, List<scanPerformanceLogDto> scanPerformanceLogs)
{
await task;
scanPerformanceLogs.Add(new scanPerformanceLogDto()
{
Area = {HERE SHOULD BE THE METHOD NAME}
Time = DateTime.UtcNow
});
}
我使用这个扩展方法来跟踪方法完成执行后的时间,如下所示:
await ProcessUnchangedElementsAsync(ob1, ob2, ob3).Log(scanPerformanceLogs);
它工作正常,除了我需要扩展方法中的名称“ProcessUnchangedElementsAsync”。怎么做呢?
答: 暂无答案
评论
Task
Task
CallerMemberName
Task.Run(...).Log()
StackTrace