I have a page that is setup like this
public partial class _Default : ViewBasePage<EmployeePresenter, IEmployeeView>,
IEmployeeView
{
...
}
Inside my base page
public abstract class ViewBasePage<TPresenter, TView> :
Page where TPresenter : Presenter<TView> where TView : IView
{
protected TPresenter _presenter;
public TPresenter Presenter
{
set
{
_presenter = value;
_presenter.View = GetView(); // <- Works
//_presenter.View = (TView)this; <- Doesn't work
}
}
/// <summary>
/// Gets the view. This will get the page during the ASP.NET
/// life cycle where the physical page inherits the view
/// </summary>
/// <returns></returns>
private static TView GetView()
{
return (TView) HttpContext.Current.Handler;
}
}
What I need to do is actually cast (TView)_Default, using my GetView() method does indeed end with that result. Inside the base page I can't do
_presenter.View = (TView)this;
Because this is actually ViewBasePage<TPresenter,TView>
so it can't directly cast to just TView.
So my actual question is there any alternative ways to achieve my result in a way that feels less hacky, if this is the primary option is there really anything I need to be concerned about by treating my page in this manner?
Edit:
The exact part I'm trying to write away is
private static TView GetView()
{
return (TView) HttpContext.Current.Handler;
}
as I feel like this is fairly gross hack to be able to reference back to the page in this context.