【问题标题】:Multiple abstract form inheritance多重抽象形式继承
【发布时间】:2016-11-11 12:02:07
【问题描述】:

我有一个抽象的基本控件BaseControl,我使用the following post解决了子窗体的不显示问题。

现在,我有很多控件共享一些公共属性,我想为其创建一个中间抽象类来重新组合不同的公共属性并强制所有后代实现一些其他属性。

[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<BaseControl, UserControl>))]
public abstract partial class BaseControl : UserControl {
  ...
  ...
  ...
}
 [TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<BaseControl2, BaseControl>))]
public abstract partial class BaseControl2 : BaseControl {
  ...
  ...
  ...
}

很遗憾,这不起作用,设计师抱怨无法为我的后代控件创建抽象类 BaseControl2 的实例。

关于如何解决这个问题的任何建议?

【问题讨论】:

  • 我不明白你的问题。你不能简单地创建一个派生自BaseControl2 的类并实例化这个类吗?
  • 我不确定我是否理解你的问题,但你可能想看看this post
  • 你能详细说明一下吗?

标签: c# winforms visual-studio windows-forms-designer


【解决方案1】:

您需要了解AbstractControlDescriptionProvider 的工作原理 - 如果类型是抽象的,它会将其替换为非抽象基类型。

你指定了一个抽象类型作为非抽象基类型,所以显然它不能工作:)

【讨论】:

  • 是的,所以我尝试用UserControl 代替BaseControl 但它也不起作用...
  • @neggenbe 好吧,您需要提供一段完整的代码来实际显示您的问题才能获得真正的帮助,但请注意 AbstractControlDescriptionProvider 不会遍历类型层次结构 - 它只是处理一个可能的抽象类。并且TypeDescriptorProviderAttribute 是继承的,所以在大多数情况下,您确实需要在整个层次结构中不超过一个 - 设计者甚至看不到第二种类型描述提供程序。
猜你喜欢
  • 1970-01-01
  • 2016-11-05
  • 2014-03-11
  • 2012-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-30
相关资源
最近更新 更多