此代码无法编译:
public class Component<T1>
{
public virtual void Foo(T1 t1)
{
return;
}
}
public class Panel<T1>
where T1: Component<Panel<T1>>
{
public void Bar() {
Console.WriteLine("Win");
}
}
public class MyFormPanel : Panel<MyFormPanel.Form>
{
public class Form : Component<MyFormPanel>
{
public override void Foo(MyFormPanel t1)
{
t1.Bar();
}
}
}
给出的错误是MyFromPanel.Form
不能用作类型参数T1,因为没有从MyFormPanel.Form
到Component<Panel<MyFormPanel.Form>>
的隐式引用转换
这似乎使我感到困惑,因为Form继承自Component,而MyFormPanel是Panel。为什么会发生此错误?