How may I reflect a type to check if it has any method in it that calls, say, the InterlockedExchange.Compare
method?
My guess is that it's not possible using simply reflection. I might need to use Roslyn or Mono.Cecil.
private static bool HasOneOrMoreMethodsThatCallInterlockedExchangeCompare(Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
if (!type.IsClass) return false;
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
foreach (var method in methods)
{
var methodBody = method.GetMethodBody();
// This is where I need help
}
return true;
}