Skip to content

Instantly share code, notes, and snippets.

@aaronjensen
Created July 16, 2009 04:13
Show Gist options
  • Save aaronjensen/148185 to your computer and use it in GitHub Desktop.
Save aaronjensen/148185 to your computer and use it in GitHub Desktop.
private static IEnumerable<Type> GetTypesInDirectoryWithExtension(string path, string extension)
{
foreach (FileInfo file in new DirectoryInfo(path).GetFiles(extension, SearchOption.AllDirectories))
{
Type[] types = null;
try
{
Assembly a = Assembly.LoadFrom(file.FullName);
types = a.GetTypes();
}
catch (ReflectionTypeLoadException err)
{
// Suggest cleaning bin directory
foreach (var loaderException in err.LoaderExceptions)
{
// log loaderException
}
throw;
}
foreach (Type t in types)
yield return t;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment