Last active
August 29, 2015 14:14
-
-
Save iBener/d023515946fad01b266c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static IPlugin LoadPlugin(string dllPath) | |
{ | |
var dllBytes = File.ReadAllBytes(dllPath); | |
var an = AssemblyName.GetAssemblyName(dllPath); | |
var assembly = Assembly.Load(dllBytes); | |
var pluginType = typeof(IPlugin); | |
foreach(Type type in assembly.GetTypes()) | |
{ | |
if(!type.IsInterface && !type.IsAbstract) | |
{ | |
if(type.GetInterface(pluginType.FullName) != null) | |
{ | |
return assembly.CreateInstance(type.FullName) as IPlugin; | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment