Visual Studio设计秀类可以继承的泛型类型? [英] Can visual studio designer show classes inheriting generic types?

查看:209
本文介绍了Visual Studio设计秀类可以继承的泛型类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图清理我们的解决方案的所有设计师的错误,冲进了以下错误:




设计者无法显示此文件,因为没有在其内的类可以被设计。设计者检查下列类文件中:DoubleAttributeTextBoxBase ---基类的NumericAttributeTextBoxBase无法加载。确保装配时已被引用,并且所有项目已建成。




类是在同一装配两个定义,所以我知道这是没有一个参考的问题。我不知道是否有什么关系的事实,基类是通用的。任何想法

 公共类DoubleAttributeTextBoxBase:NumericAttributeTextBoxBase<双> 

公共类NumericAttributeTextBoxBase< T> :文本框,其中T:IComparable的,IComparable的< T>


解决方案

一类的基类被设计必须是非 - 抽象和非通用。为了让从一个通用类可设计继承的类。解决方法是插入一个微不足道的非通用类介于两者之间:

 公共部分类DoubleAttributeTextBoxBase 
:NumericAttributeTextBoxBaseOfDouble
{
公共DoubleAttributeTextBoxBase()
{
的InitializeComponent();
}

//现在DoubleAttributeTextBoxBase是可设计。
}

公共类NumericAttributeTextBoxBaseOfDouble
:NumericAttributeTextBoxBase<双>
{
}

为使这一尽可能简单,你甚至可以把非通用类在同一个文件,你想设计的类。只要确保把它的类(如我在上面所做的),因为设计者希望在文件中的第一类是被设计的人。


I am trying to clean up all designer errors in our solutions and ran into the following error:

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: DoubleAttributeTextBoxBase --- The base class 'NumericAttributeTextBoxBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

The classes are both defined in the same assembly so I know it's not a reference problem. I'm wondering if it has anything to do with the fact that the base class is generic. Any ideas?

public class DoubleAttributeTextBoxBase : NumericAttributeTextBoxBase<double>

public class NumericAttributeTextBoxBase<T> : TextBox where T : IComparable, IComparable<T>

解决方案

The base class for a class being designed must be non-abstract and non-generic. To make a class that inherits from a generic class designable. The workaround is to insert a trivial non-generic class in-between:

public partial class DoubleAttributeTextBoxBase
    : NumericAttributeTextBoxBaseOfDouble
{
    public DoubleAttributeTextBoxBase()
    {
        InitializeComponent();
    }

    // Now DoubleAttributeTextBoxBase is designable.
}

public class NumericAttributeTextBoxBaseOfDouble
    : NumericAttributeTextBoxBase<double>
{
}

To make this as simple as possible, you can even put the non-generic class in the same file as the class you want to design. Just make sure to put it after the class (as I have done above) because the designer expects the first class in the file to be the one being designed.

这篇关于Visual Studio设计秀类可以继承的泛型类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆