Skip to content

Instantly share code, notes, and snippets.

@StephenCleary
Created May 3, 2013 00:06
Show Gist options
  • Save StephenCleary/5506394 to your computer and use it in GitHub Desktop.
Save StephenCleary/5506394 to your computer and use it in GitHub Desktop.
To search for asynchronous APIs, create a console app with this code. Reference all dlls you want to search, and then run the app in the debugger.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace DisplayAsyncAPIs
{
class Program
{
static void Main(string[] args)
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
Console.WriteLine("Searching " + assemblies.Length + " assemblies...");
var apis = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x =>
{
try { return x.GetTypes(); }
catch (ReflectionTypeLoadException ex)
{ return ex.Types.Where(t => t != null); }
}).Where(x => x.IsPublic || x.IsNestedFamily || x.IsNestedFamORAssem)
.SelectMany(x => x.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
.Where(x => (x.IsPublic || x.IsFamily || x.IsFamilyOrAssembly) && !x.IsSpecialName && x.Name.EndsWith("Async") && typeof(Task).IsAssignableFrom(x.ReturnType))
.Select(x => new
{
Name = x.DeclaringType.ToString() + "." + string.Join(" ", x.ToString().Split().Skip(1)),
Protected = x.DeclaringType.IsNestedFamily || x.DeclaringType.IsNestedFamORAssem || x.IsFamily || x.IsFamilyOrAssembly,
x.DeclaringType.Assembly
})
.OrderBy(x => x.Name).ToList();
var asyncAssemblies = apis.Select(x => x.Assembly.GetName().Name).Distinct().OrderBy(x => x).ToList();
Console.WriteLine("Found " + asyncAssemblies.Count + " assemblies:");
foreach (var assembly in asyncAssemblies)
Console.WriteLine(" " + assembly);
foreach (var api in apis.Select(x => x.Name))
Debug.WriteLine(" " + api);
Console.WriteLine("Dumped " + apis.Count + " APIs to the debugger.");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment