2

I'm analyzing a class through reflection and I want to check if a method is actually a async void method.

I have a MethodInfo object, and through it I can inspect the ReturnType property but that just says Void. Looking around I can't find a way to find to check if it's an async though.

Is there a way to see if a method is async void? Surely there must be?

David Božjak
  • 16,887
  • 18
  • 67
  • 98

1 Answers1

-1

async is not part of the method signature, and as such you won't be able to determine whether the method is async or not from it's external API.

Servy
  • 202,030
  • 26
  • 332
  • 449
  • Presence or absence of `System.Runtime.CompilerServices.AsyncStateMachineAttribute` is reliable enough in that if someone is deliberately using it explicitly it's probably sensible to consider it equivalent to having `async` on it. Wanting to know this seems strange though. – Jon Hanna Jun 11 '15 at 14:19