Ive not done any hardcore generics development so not sure how to tackle this.
I have some common functionality that i woud like available to all my usercontrols but as I inherit from the abstract class WebUserControlBase<T> with my user control and its docType im not sure how. Maybe im missing something or going about it the wrong way?
Ive tried creating a generic base class that would simply sit between them like this:
public abstract class mybase<T> : Vega.USiteBuilder.WebUserControlBase<T>
and then my usercontrol woudl inherit from my class - but the compiler dont like that.
Error1'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'Vega.USiteBuilder.WebUserControlBase<T>'
Error2The type 'T' cannot be used as type parameter 'T' in the generic type or method 'Vega.USiteBuilder.WebUserControlBase<T>'. There is no boxing conversion or type parameter conversion from 'T' to 'Vega.USiteBuilder.DocumentTypeBase'.
Error1'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'Vega.USiteBuilder.WebUserControlBase<T>'
Inheriting WebUserControlBase<T>
Ive not done any hardcore generics development so not sure how to tackle this.
I have some common functionality that i woud like available to all my usercontrols but as I inherit from the abstract class WebUserControlBase<T> with my user control and its docType im not sure how. Maybe im missing something or going about it the wrong way?
Ive tried creating a generic base class that would simply sit between them like this:
public abstract class mybase<T> : Vega.USiteBuilder.WebUserControlBase<T>
and then my usercontrol woudl inherit from my class - but the compiler dont like that.
Error 1 'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'Vega.USiteBuilder.WebUserControlBase<T>'
Error 2 The type 'T' cannot be used as type parameter 'T' in the generic type or method 'Vega.USiteBuilder.WebUserControlBase<T>'. There is no boxing conversion or type parameter conversion from 'T' to 'Vega.USiteBuilder.DocumentTypeBase'.
Any pointers anyone?
Try this:
public abstract class mybase<T> : Vega.USiteBuilder.WebUserControlBase<T>
where T: Vega.USiteBuilder.DocumentTypeBase
{
}
Still get the following error when i try that:
Error1'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'Vega.USiteBuilder.WebUserControlBase<T>'
I tried something id seen on another similar implementation and it now compiles! I'll see what happens now.
I just added: , new() on the end
public abstract class myBase: Vega.USiteBuilder.WebUserControlBasewhere T : Vega.USiteBuilder.DocumentTypeBase, new()
Will post back here if it works.
Lovely! Works perfectly. Thanks Vladan.
If you could offer a very simple explanation to how that inheritance works id appreciate it. Id like to know how that has wired things up.
is working on a reply...