I have C# application that load plugins dll and run these. All plugin inherit from BasePlugin
class. My application instantiate plugins as BasePlugin
and work with these. For example get the name of plugin, call functions and other. Exist an Interface that plugin can call API from my application and interaction with my application.
My BasePlugin
class:
public abstract class BasePlugin{
public abstract string Name {get;}
public abstract int A {get;set;}
public abstract void Do(IAPI api);
}
IAPI
Interface:
public interface IAPI
{
void F1();
int F2(int a);
}
I put IAPI
and BasePlugin
in .net library project and my application and all plugins use this library. In my project get Directory of plugins and load plugin with this code:
public List<BasePlugin> GetAllPlugins(string dir)
{
List<BasePlugin> plugins = new List<BasePlugin>();
foreach (string dll in Directory.GetFiles(dir, "*.dll"))
{
Assembly loadedAssembly = Assembly.LoadFrom(dll);
List<Type> types = loadedAssembly.GetTypes().Where(t => t.IsSubclassOf(typeof(BasePlugin))).ToList();
foreach (Type t in types)
{
plugins.Add((BasePlugin)Activator.CreateInstance(t));
}
}
return plugins;
}
I develop C# plugin easy. But how can I develop C++, Python, Java, matlab, ... plugin for my appliaction?