I know that I have to use reflection but I don't know how. I'm trying to know the MethodInfo from a StartUp Middleware. I need the MethodInfo to know if the action that I'm invoking is or is not async.
Thank you for your time.
I know that I have to use reflection but I don't know how. I'm trying to know the MethodInfo from a StartUp Middleware. I need the MethodInfo to know if the action that I'm invoking is or is not async.
Thank you for your time.
You could use reflection to judge if the method contains
AsyncStateMachineAttribute.Not sure how do you want to get this result, here are two ways:
First way
1.Create the method in anywhere:
2.Call the method in your controller:
Second way
1.Custom an ActionFilter and it will judge the method async or not before getting into the method:
2.Register the filter:
Reference:
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.asyncstatemachineattribute?view=net-5.0