[英]How can I have a class derived from a class known at runtime implementing an interface known at compilation
I think I'd be easier to just write down my pseudo-class declaration. 我想写下自己的伪类声明会更容易。
Basically, I want something like 基本上,我想要类似
public class DatabaseControlsDAL<T> : T, IDatabaseControlsDAL where T : IBaseDAL
{
public int myMethod()
{
return somePublicPropertyInTheIBaseDALInterface;
}
}
But it won't work :( 但这是行不通的:(
Any help welcome ! 任何帮助欢迎!
Generics aren't a run-time feature, thus giving a generic argument won't be a run-time issue . 泛型不是运行时功能,因此提供泛型参数不会是运行时问题 。
In the other hand, how would a class inherit what will be only known at run-time? 另一方面,类将如何继承仅在运行时才知道的内容? Think C# is a strongly-typed language. 认为C#是一种强类型的语言。
If B inherits A, but A is "unknown", then, until run-time, B won't be of type A. This defeats both the point of inheritance and polymorphism. 如果B继承了A,但是A是“未知的”,那么直到运行时,B的类型都不会变为A。这会破坏继承点和多态性。
Conclusion: if you don't provide a background in order to let us define a better solution (well, an existing solution!), you'll get this answer: you can't achieve what you're looking for in C# . 结论:如果您没有提供背景知识来让我们定义一个更好的解决方案(嗯,一个现有的解决方案!),您将得到以下答案: 您将无法实现C#的目标 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.