I have this simple code :
public interface IReader<out T>
{
IEnumerable<T> GetData();
}
This interface should be covariant on T, and i'm using it this way :
private static Func<bool> MakeSynchroFunc<T>(IReader<T> reader) where T : IComposite
{
return () => Synchronize(reader);
}
Note the constraint for T to implement IComposite.
The synchronization method takes an IReader<IComposite> in input :
private static bool Synchronize(IReader<IComposite> reader)
{
// ......
}
The compiler tells me it cannot convert from IReader<T> to IReader<IComposite> despite the constraint on T and the covariance of IReader.
Is there something i'm doing wrong here ?
The compiler should be able to verify the constraint and the covariance should let me use my IReader<T> as an IReader<Icomposite>, isn't it ?
Thanks.