与继承的接口相关的无法转换

时间:2019-03-25 11:38:32

标签: c#

我收到以下错误消息:

  

无法从“ RemoteFilesWatcherService”转换为   “ IWatcherService”

它在以下行上引发:

var coll = new CollectionService(fileWatcherService);

这是我下面的代码结构。

我不明白为什么我不能仅仅将RemoteFilesWatcherService作为CollectionService传递到IWatcherService<IEntity>的ctor中,因为RemoteFilesWatcherService实现了IRemoteFilesWatcherService,它继承自{{1} }对我来说应该可以使用。

IWatcherService<RawDataFile>

编辑:

public interface IWatcherService<TDataEntity> where TDataEntity : IEntity
{
    void Watch();
    INotificationFactory NotificationFactory { get; }
    ObservableCollection<TDataEntity> MatchingEntries { get; set; }
}


public interface IRemoteFilesWatcherService : IWatcherService<RawDataFile>
{
     IRemoteFilesRepository<IDbManager, RawDataFile> RemoteFilesRepository { get; }
}

public class RemoteFilesWatcherService : IRemoteFilesWatcherService
{
}

class CollectionService
{

    private IWatcherService<IEntity> _watcherService;

    public CollectionService(IWatcherService<IEntity> watcherService)
    {
        _watcherService = watcherService;
    }
}

class Run
{
    void DoIt()
    {
        var fileWatcherService = new RemoteFilesWatcherService();
        var coll = new CollectionService(fileWatcherService);
    }
}

0 个答案:

没有答案