3

i'm trying to declare bindingSource as generic in a control generic

public partial class ABMControl<T> : UserControl
{
    public ABMControl()
    {
        InitializeComponent();
    }
}
partial class ABMControl<T>
{
    ...
    private void InitializeComponent()
    {
        ...
        this.bindingSource.DataSource = typeof(T)
        ...
    }
    ...
}

But in the designer this is the problem:

Failed to parse method 'InitializeComponent'. The parser reported the following error 'Type parameters are not suppported Parameter name: typeSymbol'. Please look in the Task List for potential errors.

But in the designer this is the problem

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Federico Fia Sare
  • 1,166
  • 2
  • 8
  • 15

1 Answers1

3

To prevent designer error, set data source of binding source in constructor.

When you put a piece of code in constructor of your control designer deserializer will not try to parse it. It also will not run in design time of your control, while in run-time and also for derived control, it will run.

Here is what you should have to prevent error:

public partial class ABMControl<T> : UserControl
{
    public ABMControl()
    {
        InitializeComponent();
        this.bindingSource.DataSource = typeof(T)
    }
}

For more information about how designer works take a look at the following post, specially take a look at the example which contains a couple of errors but shows the designer:

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398