-2

我有两个项目 P1 和 P2(ClassLibrary 项目)。我将 P2 添加到 P1 的引用中。我需要从 P2 项目中的 P1 获取方法。

我尝试这样做:

//P1 project class Commands

 class Commands:ICommands
 {
    public void Somemethod()
    {......}
 }
 //P2 project
 interface ICommands
 {
  void Somemethod(); 
 }
 class UserControl1:UserControl
 {
  ICommands _commands
  public void setCommands(ICommands com)
  {
   _commands=com;
  }
  private void button1_Click(object sender, EventArgs e)
    {

        _commands.Somemethod();


    }
 }

但是当我按下button1时我有异常:

你调用的对象是空的。

这是 autoCad 插件。P1 从 P2 加载调色板,但调色板按钮的命令在 P1 项目中。

当 AutoCAD 运行时,调色板加载。当我按下按钮并尝试调用 Somemethod(); 时出现此错误 所有错误文本:

您的应用程序的组件中发生了未处理的异常。如果单击继续,应用程序将忽略此错误并尝试继续。你调用的对象是空的。

Somemethod() 必须在 AutoCad AutoCad 中运行新绘图 仅使用一个 dll(P1 项目)从第二个 dll(P2 项目)加载 UI 调色板我需要从第一个 .dll(P1 项目)加载调色板的方法

4

1 回答 1

0

在 P1 定义一个具有静态方法的类

从 P2(已在 AutoCAD 上加载)加载 P1,然后调用 P1 Class.Method()

于 2015-04-29T13:08:05.717 回答