我想为我的一些自定义的抽象基类UserControl
。原因很明显:它们共享一些共同的属性和方法(实际上是接口某些元素的基本实现),而我只想实现它们一次。
我通过定义我的抽象基类来做到这一点:
public abstract class ViewBase : UserControl, ISomeInterface
然后我去实现我的一个观点,像往常一样,和设计师一起:
public partial class SpecialView : UserControl //all OK
到这里一切都很好。现在我用SpecialView
抽象基类替换我的类的派生:
public partial class SpecialView : ViewBase //disrupts the designer
现在,Visual Studio 2008 中的设计器将不再工作,说明:The designer must create an instance of type 'ViewBase' but it cannot because the type is declared as abstract.
我该如何规避这个?我只是不想为所有这些视图复制相同的代码。
信息:有一个虚拟方法的问题,而不是抽象类,但没有适合我的解决方案。