泛型破坏了设计器,因为它无法实例化没有类型的类T
。我在我的博客文章中解释了一种解决方法:
http://adamhouldsworth.blogspot.co.uk/2010/02/winforms-visual-inheritance-limitations.html
简而言之,您需要使用中间类“解析”类型:
BaseControl<T> : UserControl
CustomerControl_Design : BaseControl<Customer>
CustomerControl : CustomerControl_Design
DEBUG
然后,您可以根据或RELEASE
编译器开关有条件地将此类从代码中切换出来:
#if DEBUG
namespace MyNamespace
{
using System;
public partial class CustomerEditorControl_Design : BaseEditorControl<Customer>
{
public CustomerEditorControl_Design()
: base()
{
InitializeComponent();
}
}
}
#endif
public partial class CustomerEditorControl
#if DEBUG
: CustomerEditorControl_Design
#else
: BaseEditorControl<Customer>
#endif
{
}
This will let you open the derived class of CustomerControl
, unfortunately you will never be able to design a UI control with generics in the signature. My solution is only enabling the design of derived items.
I have no idea why CustomerControl : BaseControl<Customer>
won't work as in this case the type T
is defined, but it simply doesn't - I'm guessing because of the rules of generic usage.
To their defense, Microsoft do say that this isn't supported.