I'm dealing with a Winforms problem while I'm trying to refactor the code. The code-behind of the form looks like this:
namespace SIC.AplicacionEscritorio.MySolution
{
public partial class A : B
{
public A(Document document)
: base(document)
{
//definition for constructor
}
public override void Method1()
{
//definition for method1 in form
}
protected override void Method2()
{
//definition for method2 in form
}
}
public class B : C <Scheme.SomeDataTable, Scheme.SomeRow>
{
public B() { }
public B(Document document) : base(document) { }
public override void Method1()
{
throw new NotImplementedException(); //this is SO ugly
}
protected override void Method2()
{
throw new NotImplementedException();
}
}
public abstract class C <T, R> : Form
where T : DataTable, new()
where R : DataRow
{
public C(Document document)
: this()
{
//main constructor
}
public abstract void Method1();
protected abstract void Method2();
}
}
If you look the code, it seems that class B is not really needed. C is the class which inherits from Form.
According with those questions:
"Illegal characters in path." Visual Studio WinForm Design View "the designer doesn't support base forms that are generic"
Generic forms and VS designer "Generics break the designer because it cannot instantiate the class without a type T"
So, In order to refactor the code, I tried to do something like this, but it throws an error "Illegal characters in path." (same as 1st question).
namespace SIC.AplicacionEscritorio.MySolution
{
public partial class A : C <Scheme.SomeDataTable, Scheme.SomeRow>
{
public A(Document document)
: base(document)
{
//definition for constructor
}
public override void Method1()
{
//definition for method1 in form
}
protected override void Method2()
{
//definition for method2 in form
}
}
public abstract class C <T, R> : Form
where T : DataTable, new()
where R : DataRow
{
public C(Document document)
: this()
{
//main constructor
}
public abstract void Method1();
protected abstract void Method2();
}
}
Apparently, we have to create an intermediary class that allows the designer to create the instance, but I need to say that it doesn't looks really nice. The question is:
Do I need to leave the code as it was? Is there some object-oriented trick to solve it?