当我想向上base
转换到适当的接口类型(即A
)以便我可以在其上调用 doA() 时,我得到一个解析错误。我知道base
(http://cs.hubfs.net/topic/None/58670)有点特别,但到目前为止我还没有找到解决这个特定问题的方法。
有什么建议么?
type A =
abstract member doA : unit -> string
type ConcreteA() =
interface A with
member this.doA() = "a"
type ExtA() =
inherit ConcreteA()
interface A with
override this.doA() = "ex" // + (base :> A).doA() -> parse error (unexpected symbol ':>' in expression)
((new ExtA()) :> A).doA() // output: ex
工作的 C# 等价物:
public interface A
{
string doA();
}
public class ConcreteA : A {
public virtual string doA() { return "a"; }
}
public class ExtA : ConcreteA {
public override string doA() { return "ex" + base.doA(); }
}
new ExtA().doA(); // output: exa