I have the following classes defined (code redacted for brevity)
public interface ICollectionItem
{}
Which in turn is inherited by:
public class CollectionItem : NotifyPropertyChanged, ICollectionItem
{}
And in turn is inherited by:
public class DeviceItem : CollectionItem, IDisposable, IAsyncDisposable
{
public DeviceItem(DeviceCollectionBase<ICollectionItem> deviceCollection)
{}
}
Which has a constructor so i can then create a DeviceItem
instance from within yet another class:
public abstract class DeviceCollectionBase<T> : PacedItemCollection<T>, IDisposable, IAsyncDisposable where T : ICollectionItem
{
protected override async Task UpdateCollection()
{
var v = new DeviceItem(this)...
}
}
But the parameter this
is flagged with the error CS1503
"Argument type DeviceCollectionBase<T>, is not assignable to parameter type DeviceCollectionBase<ICollectionItem>
, yet T
is constrained to be an ICollectionItem
.
So here we have the parameter definition asking for an ICollectionItem
and the parameter passed implementing from an ICollectionItem
My covariance and/or contravariance games are shite, so i don’t quite see where im going wrong, nor how to work around the issue, any help please?