Consider the following:
class ControllerFactoryBase<P> : where P : PledgeReadOnly
{
public void Foo()
{
PledgeRepositoryReadOnly<P> repos = PledgeRepository();
new AdminController(repos); // compilation error here
}
}
public interface PledgeRepositoryReadOnly<out P> where P : PledgeReadOnly
{
IEnumerable<P> GetPledgesToBeneficiary();
}
public class AdminController
{
public AdminController(PledgeRepositoryReadOnly<PledgeReadOnly> pledgeProvider)
{ ... }
}
I'm getting a compilation error on the instantiation of AdminController with message:
cannot convert from 'PledgeRepositoryReadOnly<P>' to 'PledgeRepositoryReadOnly<PledgeReadOnly>'
and I'm not sure why. I believe this substitution is safe. Can you help me understand why it is not?
edit more digestible presentation: http://csharppad.com/gist/9283391
PledgeRepository();' I argue this is irrelevant though because there is no error on the repos assignment line.
– Dejas Feb 28 '14 at 06:43: PledgeRepositoryReadOnly
where P : PledgeReadOnly',i use this,and everything is ok
– chenZ Feb 28 '14 at 07:07