views:

32

answers:

0

Hello folk,

Lets start at the beginning :) I added a covariant interface to our project:

interface IView
{
}

interface IPresenter<out TView> where TView : IView
{
    TView View { get; }
}

I created some classes, implementing these interfaces:

class TestView : IView
{
}

class TestPresenter : IPresenter<TestView>
{
  public TestView View
  {
    get { return something; }
  }

  private void DoSomething()
  {
  }
}

And I can use this without problems:

IPresenter<IView> presenter = new TestPresenter();

So everything seems right, so I assume my covariance usage is correct. Unfortunately our unit test projects contain private accessors from some types located in the same project like the covariant interface, which causes a build failure.

Could not load type 'GenericInheritanceTest.IPresenter_Impl`1' from assembly 'GenericInheritanceTest_Accessor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because it declares a covariant or contravariant type parameter and is not an interface or delegate.

What exactly is the problem here? Is there a failure in my implementation, resp. how to fix this? Can not be, that we have to avoid accessors as soon as we use covariant types??? Is it possible to prevent creating accessors for certain types to solve this problem?

Thanks for help, Enyra