I want to get the name of this method by using Reflection etc...I use a lot of stuff but I 'm tired please help me. If the function is sync then it below code will work fine. Please go through the below code, that will clear you my question.
// 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; });
}
This method provide me Name of non async method. but how I get above method name
> [MethodImpl(MethodImplOptions.NoInlining)]
> public static string GetCurrentMethod()
> {
> var stackTrace = new StackTrace();
> StackFrame stackFrame = stackTrace.GetFrame(1);
> return stackFrame.GetMethod().Name;
> }
But this method is working only for not async method. So how get current async method name in c#