Skip to content

Instantly share code, notes, and snippets.

@richlander
Created December 4, 2018 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richlander/c6322355aca331795a78116b0cba5460 to your computer and use it in GitHub Desktop.
Save richlander/c6322355aca331795a78116b0cba5460 to your computer and use it in GitHub Desktop.
Assembly Metadata Reading with MetadataLoadContext Example
var paths = new string[] {@"C:\myapp\mscorlib.dll", @"C:\myapp\myapp.dll"};
var resolver = new PathAssemblyResolver(paths);
using (var lc = new MetadataLoadContext(resolver))
{
Assembly a = lc.LoadFromAssemblyName("myapp");
Type myInterface = a.GetType("MyApp.IPluginInterface");
foreach (Type t in a.GetTypes())
{
if (t.IsClass && myInterface.IsAssignableFrom(t))
Console.WriteLine($"Class {t.FullName} implements IPluginInterface");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment