UserControl abstract shared inheritance in Visual Studio Designer

In one of my projects, I use an abstract UserControl. To create this control in Visual Studio, I use the code suggested in this answer . Now I want to use this with another abstract UserControl, which is also shared. But if I do

[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<MyBaseControl<T>, UserControl>))]

I get a compiler error

CS0416: attribute argument cannot use type parameters

Deleting a type parameter obviously also does not compile.

I cannot derive MyBaseControl from a non-generic base class, because it is already derived from the base base class, so I tried to decorate it with an interface and use it like this:

[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<IMyBaseControl, UserControl>))]

, , ,

.

?

+3
1

, AbstractGenericBase<T> : GenericBase<T>, GenericBase<T> , : GenericBase<T>: UserControl.

, AbstractGenericBase<T> , :

using System.ComponentModel;
using System.Windows.Forms;

#if DEBUG
public abstract partial class AbstractGenericBase<T> : NonGenericBase
#else
public partial class AbstractGenericBase<T> : GenericBase<T>
#endif
{
    public AbstractGenericBase()
    {
        InitializeComponent();
    }
}
#if DEBUG
public class NonGenericBase : GenericBase<object> { }
#endif

  • :
    public abstract partial class AbstractGenericBase<T> : GenericBase<T>
  • T , object GenericBase<object> Dummy, .
  • : , . , , .
    , NonGenericBase, GenericBase<T> .
+1

Source: https://habr.com/ru/post/1660490/


All Articles