我试图拥有一个基本的
Windows Forms表单,它具有常用的功能和控件 – 而且还包含对需要类型为其方法的类的引用.每个表单都会代表不同的类型,所以我认为我可以按照这样做做一些事情:
public partial class Base<T> : Form where T : BaseClass { private GenericHandler handler = new GenericHandler(); } public class BaseClass { } public class GenericHandler { public void DoSomethingWithInstance<T>(T instance) where T : BaseClass { } }
我的设计师类声明也反映了我的形式.现在当我做了代表Foo类型的第二个表单时,我无法访问设计器,因为我收到这个错误:
The designer could not be shown for this file because none of the
classes within it can be designed. The designer inspected the
following classes in the file: Foo — The base class
‘WindowsFormsApplication1.Base’ could not be loaded. Ensure the
assembly has been referenced and that all projects have been built.FooClass — The base class ‘WindowsFormsApplication1.BaseClass’
cannot be designed.
public partial class Foo : Base<FooClass> { public Foo() { InitializeComponent(); } } public class FooClass : BaseClass { }
为什么会发生这种情况/我做错了什么或有什么其他方法可以做到这一点?