如何在没有引用的情况下使用另一个项目的方法
How use method from another project without references
我有两个项目 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();
}
}
但是当我按下按钮 1 时出现异常:
Object reference not set to an instance of an object.
这是 autoCad 插件。 P1 从 P2 加载调色板,但调色板按钮的命令在 P1 项目中。
当 AutoCad 运行 时,调色板加载。当我按下按钮并尝试调用 Somemethod() 时出现此错误;
所有错误文本:
Unhandled exception has occurred in a component in your application. If you click Continue, the application will ignore this error and attempt to continue.
Object reference not set to an instance of an object.
Somemethod() 必须 运行 在 AutoCad 中新建绘图
AutoCad 仅使用一个 dll(P1 项目)UI 从第二个 dll(P2 项目)加载调色板我需要从第一个 .dll(P1 项目)加载调色板的方法
在 P1 定义一个 class 静态方法
从 P2(已加载到 AutoCAD 上)加载 P1,然后调用 P1 Class.Method()
我有两个项目 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();
}
}
但是当我按下按钮 1 时出现异常:
Object reference not set to an instance of an object.
这是 autoCad 插件。 P1 从 P2 加载调色板,但调色板按钮的命令在 P1 项目中。
当 AutoCad 运行 时,调色板加载。当我按下按钮并尝试调用 Somemethod() 时出现此错误; 所有错误文本:
Unhandled exception has occurred in a component in your application. If you click Continue, the application will ignore this error and attempt to continue. Object reference not set to an instance of an object.
Somemethod() 必须 运行 在 AutoCad 中新建绘图 AutoCad 仅使用一个 dll(P1 项目)UI 从第二个 dll(P2 项目)加载调色板我需要从第一个 .dll(P1 项目)加载调色板的方法
在 P1 定义一个 class 静态方法
从 P2(已加载到 AutoCAD 上)加载 P1,然后调用 P1 Class.Method()