我遇到了一个问题.我在我的程序中使用外部库提供了一个接口,IStreamable(我没有这个接口的源代码).
然后我在我创建的DLL中实现接口,DFKCamera类.
在我当前的程序中(遗憾的是我无法完全修改因为我只是为它编写插件)然后我只能访问在IStreamable接口中定义的DFKCamera方法.但是,我需要访问我在DFKCamera中编写的另一种方法,以便我的插件工作(程序的其余部分不使用的方法,因此在IStreamable中没有定义).
是否可以在C#中扩展接口的定义?如果我可以扩展IStreamable接口,那么我就可以访问新方法了.
就是这样的情况:
//In ProgramUtils.DLL, the IStreamable interface is defined
//I have only the .DLL file available
namespace ProgramUtils {
public interface IStreamable {
//some methods
}
}
//In my DFKCamera.DLL
using ProgramUtils;
class DFKCamera: IStreamable {
//the IStreamable implementation code
....
//the new method I wish to add
public void newMethod() {}
//In the the program that uses DFKCamera.DLL plugin
//The program stores plugin Camera objects as IStreamable DLLObject;
IStreamable DLLObject = new DFKCamera();
//This means that …Run Code Online (Sandbox Code Playgroud)