Skip to content

Instantly share code, notes, and snippets.

@iBener
Last active August 29, 2015 14:14
Show Gist options
  • Save iBener/d023515946fad01b266c to your computer and use it in GitHub Desktop.
Save iBener/d023515946fad01b266c to your computer and use it in GitHub Desktop.
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