请告诉我如何从dll调用方法,你甚至可以使用通常的原始MessageBox.Show(" Hello MessageBox"); 。 如果有的话,我加载了库...
private void LoadPlugins(string path)
{
string[] files = Directory.GetFiles(path, "*.dll");
foreach (string fname in files)
{
Assembly asm = Assembly.LoadFrom(fname);
foreach (Type t in asm.GetExportedTypes())
{
if (typeof(PluginIface.IPlugin).IsAssignableFrom(t))
{
PluginIface.IPlugin pi = (PluginIface.IPlugin)asm.CreateInstance(t.FullName);
pi.shwdialog(); // Here the window should appear)
}
}
}
}
带有界面的文件。
namespace PluginIface
{
public interface IPlugin
{
void shwdialog();
}
}
文件插件
namespace plg
{
public class Plugin1 : IPlugin
{
public Plugin1()
{
System.Console.WriteLine("Plugin1 start");
}
public void shwdialog()
{
MessageBox.Show("Hello MessageBox");
}
}
}