具有泛型类型的ObservableCollection不起作用

时间:2018-06-14 23:57:08

标签: c#

我不知道我是否理解错了。但Visual Studio表示添加项目不允许从ExporterTaskWorker<ExporterTypeMusic>转换为ExporterTaskWorker<IExporterType>。但是ExporterTypeMusic实现了IExporterType接口。 我做错了什么?

public interface IExporterType
{
    bool BrandChannelAssigning();
}

public class ExporterTypeMusic : IExporterType
{
    public bool BrandChannelAssigning()
    {
        throw new System.NotImplementedException();
    }
}

public class ExporterTaskWorker<T> : INotifyPropertyChanged where T : IExporterType
{
    public Config TheConfig { get; set; }

    public object SomeProperty { get; set; }
    ...
    ...

    public ExporterTaskWorker(Config _config) {

    }
}



public class SomeClass
{
    public ObservableCollection<ExporterTaskWorker<IExporterType>> ExporterInstanceCollection { get; set; } = new ObservableCollection<ExporterTaskWorker<IExporterType>>();

    public void SomeMethod()
    {
        Config theConfig = new Config();
        ExporterTaskWorker<ExporterTypeMusic> exporterTaskWorker = new ExporterTaskWorker<ExporterTypeMusic>(theConfig);

        ExporterInstanceCollection.Add(exporterTaskWorker);

    }
}

0 个答案:

没有答案