我在 DerivedFileInfo 类声明中遇到错误。
错误:类型“StorageManager.Test.DerivedStorageProvider”不能用作泛型类型或方法“StorageManager.Test.BaseFileInfo”中的类型参数“TStorageProvider”。没有从“StorageManager.Test.DerivedStorageProvider”到“StorageManager.Test.IStorageProvider”的隐式引用转换。
通用约束是否缺少某些东西,或者我需要通用协变?
public interface ICacheProvider
{
}
public class BaseCacheProvider : ICacheProvider
{
}
public class DerivedCacheProvider : BaseCacheProvider
{
}
public interface IStorageProvider<TCacheProvider> where TCacheProvider : ICacheProvider
{
}
public abstract class BaseStorageProvider<TCacheProvider> : IStorageProvider<TCacheProvider> where TCacheProvider : ICacheProvider
{
}
public class DerivedStorageProvider : BaseStorageProvider<DerivedCacheProvider>
{
}
public interface IResourceInfo<TStorageProvider> where TStorageProvider : IStorageProvider<ICacheProvider>
{
}
public abstract class ResourceInfo<TStorageProvider> : IResourceInfo<TStorageProvider>
where TStorageProvider : IStorageProvider<ICacheProvider>
{
}
public abstract class BaseFileInfo<TStorageProvider> : ResourceInfo<TStorageProvider> where TStorageProvider : IStorageProvider<ICacheProvider>
{
}
public class DerivedFileInfo : BaseFileInfo<DerivedStorageProvider>
{
}