Solved

trying to store a pointer to my presenter in view class

Posted on 2013-06-20
1
221 Views
Last Modified: 2013-06-24
Here's my presenter class:

public class ListPresenter<TViewInterface, TContext> : Presenter<TViewInterface, TContext>
            where TViewInterface : IContextView<TContext>, IListView
            where TContext : IObservableObject
{
     protected override void OnInitializePresentationComplete(dynamic data)
     {
      View.ViewPresenter = (ListPresenter<TViewInterface, TContext>)this;
     }
}

Here's how I am defining the property in the view:

public ListPresenter<IListView, IObservableObject> ViewPresenter { get; set; }

The compile time exception showing on the ViewPresenter property is "The type IListView cannot be used as type parameter TViewInterface in the generic type or method ListPresenter<TViewInterface, TContect>.  There is no implicit reference conversion from IListView to IContextview<IObservableObject>.

Am I defining the ViewPresenter incorrectly?  Or am I not casting it correctly?  Or both?
0
Comment
Question by:FrancineTaylor
1 Comment
 
LVL 1

Accepted Solution

by:
FrancineTaylor earned 0 total points
ID: 39272174
I finally figured out how to do what I needed to.  I wanted to give my view direct access to methods in the presenter, but what I was missing was the presenter contract.  I defined an interface for the presenter, IListPresenter, and had the presenter inherit from it.  After that it became simple to cast the presenter and store the pointer.

So my presenter definition now looks like this:

public class ListPresenter<TViewInterface, TContext> : Presenter<TViewInterface, TContext>, IListPresenter
      where TViewInterface : IContextView<TContext>, IListView
      where TContext : IObservableObject
{
      public ListPresenter()
      {
            View.ViewPresenter = (IListPresenter)this;
      }

...and the base view's property...

public IListPresenter ViewPresenter { get; set; }
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question