ale*_*lex 4 c# forms windows plugins
您好
我有一个主应用程序将在./plugin目录中有一些插件.
每个插件都是.NET dll,应该具有命名空间"Plugin"和实现主应用程序中定义的IPlugin接口的类"MainClass".
我的问题是,我不知道我怎么能分享横跨主应用程序和每个插件都相同的接口没有一个using参考?
主app类的一部分:
object oo = Assembly.LoadFile(path).CreateInstance("Plugin.MainClass");
IPlugin pp = (IPlugin)oo; //Fails if I define the interface in the main app and the plugins
Run Code Online (Sandbox Code Playgroud)
和第一个插件的一部分:
namespace Plugin
{
public class MainClass : IPlugin //I cannot reference the interface in the main app?
{
public string getName()
{
return "Plugin 1";
}
}
}
Run Code Online (Sandbox Code Playgroud)
你是正确的使用接口(或类,结构等...)你必须引用该程序集.如果您不希望您的插件引用主应用程序(这是有道理的)为什么不为此目的添加新的程序集?称它为'框架'或'util'.
例如
Run Code Online (Sandbox Code Playgroud)Framework Assembly - IPlugin PluginOne Assembly (references Framework) - PluginOne : IPlugin Main App Exe (references PluginOne & Framework assemblies)
| 归档时间: |
|
| 查看次数: |
4744 次 |
| 最近记录: |