Winforms Designer with generic forms support

Nov 8, 2013 at 2:41 PM
I have found this framework very useful. However, as mentioned in a number of threads in the CodeProject discussions related to this project, the winforms designer in VS does not support use of generic types in immediately inherited classes, complaining that the parent class is not designable. This means that the use of
public class MyMVPAppForm : WinFormsMVP.Forms.MvpForm<MyMVPAppModel>, IMyMVPAppView

will prevent any designer usage.

There is a solution, as found in the link below, which appears to overcome this issue:
http://madprops.org/blog/Designing-Generic-Forms/

basically, put an intermediary class, that is not itself using generics, which is based on the problematic generic using class, as below:

MyMVPAppIntermediaryForm : WinFormsMVP.Forms.MvpForm<MyMVPAppModel>
{
//do nothing
}
and change the form that you require designer support for to reference the intermediary, i.e.

MyMVPAppForm : MyMVPAppIntermediaryForm, IMyMVPAppView


As the designer doesn't immediately see an issue with lack of generics support from the base class, it will successfully load the form.

Although a small irritation in requiring creation of the intermediary classes, I think the massive gains from using this framework in separation of concerns is very much worth it. Takes a little while to get the concepts if you are not familiar but soon pays off. Thanks for creating the framework, and thanks also to Matt Hamilton for above generic forms designer issue solution.