Is it Possible to Make a Generic Control in .Net 3.5?

后端 未结 4 1602
渐次进展
渐次进展 2020-12-09 12:12

I\'ve got the following Generic usercontrol declared:

public partial class MessageBase : UserControl
    {
        protected T myEntry;
        publ         


        
4条回答
  •  孤街浪徒
    2020-12-09 12:56

    The .NET framework supports them, but as Vilx mantions, the designers simply do not - and any of the xml/markup-based platforms (xaml (wpf) or ASP.NET) will not like generics at all. So the best advice is: don't use them.

    A common compromise is to have a Type property (or an object template-property upon which you call GetType()), and simply cast etc inside the control. Likewise, such usage will commonly make use of things like Activator.CreateInstance, and TypeDescriptor (for metadata lookup etc).

提交回复
热议问题