I have these classes:
class Foo<T1, T2> : Form
where T1, T2 : EventArgs
class MiddleGoo : Foo<X,Y>
class Goo : MiddleGoo
X,Y are just simple classes derived from EventArgs.
I see Goo in designer, but i want to create a class Boo between Foo and Goo like this:
class Boo<T1, Y> : Foo<T1, Y>
where T1 : EventArgs
class MiddleGoo : Boo<X,Y>
class Goo : MiddleGoo
Workaround with middle class doesn't work, any ideas?
EDIT: I meant Y and X are classes like YEventArgs and XEventArgs and my problem is about seeing in designer class Boo when i defined Y as T2 but still want to keep it generic through T1.
EDIT2: I just realized I misspelled something about Y class...
public class Foo<T1, T2> : Form
where T1 : EventArgs
where T2 : EventArgs
{
}
public class Boo<T1> : Foo<T1, MyEventArgs2>
where T1 : EventArgs
{
}
public class MiddleGoo : Boo<MyEventArgs1>
{
}
class Goo : MiddleGoo
{
}
public class MyEventArgs2 : EventArgs
{
}
public class MyEventArgs1 : EventArgs
{
}
And to be clear I just can't see Boo in Designer... ( I can't see MiddleGoo too but i don't need to)
Foo
hasn't changed, the second piece of code is surely invalid asY
does not inherit fromEventArgs
. Is that your "between" class? This looks like an X-Y problem. What are you trying to do? The Winforms designer doesn't like forms, let alone inherited forms with generic arguments. – Bolandclass Boo<T1, Y> : Foo<T1, Y> where T1 : EventArgs
is only valid if you addY:EventArgs
too, hereY
is a generic parameter name, It is not theY
that you said inherits fromEventArgs
– Tookclass Boo<T1, YEventArgs> : Foo<T1, YEventArgs> where T1 : EventArgs
thatYEventArgs
is not yourYEventArgs
class, it is just a generic parameter likeT
orK
, also there is an Error The type'YEventArgs'
cannot be used as type parameter 'T2' in the generic type or method'Foo<T1,T2>'
. There is no boxing conversion or type parameter conversion from'YEventArgs'
to'System.EventArgs'
. – TookBoo<T1>
in designer. And alsoMiddleGoo
your class must have a non-generic base can show in designer. Check my answer. – TookBaseForm<T>:Form
will show, butMyForm:BaseForm<T>
will not show. And It is not my fault ;) – Took