Created
December 4, 2018 17:08
-
-
Save richlander/c6322355aca331795a78116b0cba5460 to your computer and use it in GitHub Desktop.
Assembly Metadata Reading with MetadataLoadContext Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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