Solved

trying to store a pointer to my presenter in view class

Posted on 2013-06-20
1
216 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now