I'm trying to understand why the following will not compile. The compiler complains on the line where CreatePresenter tries to set the View property:
Cannot implicitly convert type 'Sandbox.Program.MyView' to 'TView'.
I know the context of the assignment does not make sense, it's more for illustration. Any help would be great!
interface IView {
}
class Presenter<T> where T : IView {
public T View { get; set; }
}
class MyView : IView {
}
class MyPresenter : Presenter<MyView> {
public MyPresenter() { }
}
class ViewBase<TPresenter, TView>
where TPresenter : Presenter<TView>, new()
where TView : IView {
public TPresenter Presenter { get; private set; }
void CreatePresenter() {
this.Presenter = new TPresenter();
this.Presenter.View = new MyView();
}
}
MyView
?