Solved

trying to store a pointer to my presenter in view class

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

16 Experts available now in Live!

Get 1:1 Help Now