c# - 将接口转换为泛型类(继承)
问题描述
我在代码中有以下结构:
AController<S> : IScreenController where T : IProperties {}
FOOTypeControllers<T> : AController<T> where T : IScreenProperties
{
}
MyFooTypeController : FOOTypeControllers<MyProperties>
{
}
class MyProperties : IProperties {}
我想要做的是将 MyFooTypeController 类型转换为 FOOTypeControllers 但我得到一个无效的转换错误。为什么不允许这样做,因为它确实从类继承。
这正是我试图投射的方式:
void MyFucntion(IScreenController screenController)
{
FOOTypeControllers<IProperties> screenControl = (FOOTypeControllers<IProperties>) screenController
}
FOOTypeControllers 的每个子类也将使用 Iproperties 的不同子类。
解决方案
推荐阅读
- c++ - 尝试在 opencv 4.5.1 中使用 SIFT 提取特征时出现问题
- myhdl - MyHDL 0.11 在一个简单的解复用器实现上出错
- ios - 如何使用预定功能更改 Firestore 文档中的布尔值?
- python - 如何在显示 QMenu 时将鼠标焦点转移回来?
- javascript - 数组javascript中具有相同id值的超大数据
- c++ - C++:用于创建聚合类的结构设计模式,其成分表达了他们想要公开的内容
- java - 从 OpenJDK16 读取使用 keytool 创建的 PKCS12 密钥库时,Java 8 中的 IOException
- java - 不支持 Android 改造映射器 3.x
- java - 在 Java 中,为什么要在构造函数之外初始化一个数据字段,然后在构造函数内部给它一个不同的值?
- c# - BenchmarkDotNet 在遇到奇怪的解决方案结构时无法找到测试