【发布时间】:2016-11-10 18:42:47
【问题描述】:
在我的一个项目中,我使用了一个抽象的 UserControl。为了能够在 Visual Studio 中设计此控件,我使用了this answer 中提出的代码。现在我想将它与另一个通用的抽象 UserControl 一起使用。但是如果我这样做了
[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<MyBaseControl<T>, UserControl>))]
我收到编译器错误
CS0416:属性参数不能使用类型参数
删除类型参数显然也不会编译。
我不能从非泛型基类派生 MyBaseControl,因为它已经从泛型基类派生,所以我尝试用接口装饰它并像这样使用它:
[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<IMyBaseControl, UserControl>))]
这个确实编译但是当我打开设计视图时我的控件没有被渲染,而是我得到了错误
提供的泛型参数的数量不等于泛型类型定义的数量。
有没有办法解决这个问题?
【问题讨论】:
-
Arributes 与泛型的工作方式不同,因此为什么
[TypeDescriptionProvider(typeof因为它不能使用泛型
标签: c# winforms visual-studio windows-forms-designer designer