?
Solved

trying to store a pointer to my presenter in view class

Posted on 2013-06-20
1
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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