Annoying duplication in derived classes
In each form we get from FormBaseControl
, we have the following code. I'm sure there is a better way to typeset a controller object than this one, but for now we've included it in every page. The example below base.Controller
is of the type BaseController
from which it is inferred ExportController
. I find this code duplicated in every expression FormBaseControl
so as not to smell to the right, but I can't figure out exactly how to fix it.
private ExportController MyController
{
get { return base.Controller as ExportController; }
}
protected void Page_Load(object sender, EventArgs e)
{
base.Controller = new ExportController(WebNavigator.Current);
source to share
Can't you use a generic class to fix this?
those. instead:
private ExportController MyController
{
get { return base.Controller as ExportController; }
}
in a derived class.
Placed:
protected T MyController
{
get { return this as T; }
}
in the base class and turn the base class into a generic class BaseController<T>
source to share