是有可能使在.NET 3.5中一个通用控制? [英] Is it Possible to Make a Generic Control in .Net 3.5?
本文介绍了是有可能使在.NET 3.5中一个通用控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下一般用户控件声明:
I've got the following Generic usercontrol declared:
public partial class MessageBase<T> : UserControl
{
protected T myEntry;
public MessageBase()
{
InitializeComponent();
}
public MessageBase(T newEntry)
{
InitializeComponent();
myEntry = newEntry;
}
}
}
不过,编译器不会允许我这样做:
But the compiler won't allow me to do this:
public partial class MessageControl : MessageBase<Post>
{
public MessageControl()
{
InitializeComponent();
}
}
如何创建在C#泛型的用户控制?
How do I create a generic user control in C#?
推荐答案
试试这个
public partial class MessageControl : MessageControlBase
{
public MessageControl()
{
InitializeComponent();
}
}
public class MessageControlBase : MessageBase<Post>
{}
的关键,让设计师的工作是该类的您正在编辑的基类绝不能通用的。
The key to getting the designer to work is that the base class of the class you are editing must not be generic.
这篇关于是有可能使在.NET 3.5中一个通用控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文