假设我在C#中有这个界面,并希望在F#
中实现它public interface IBatch
{
System.Data.IDbConnection Connection { get; set; }
}
我希望在F#中实现接口,但无法找出正确的语法。我有这样的事情:
type public Batch =
interface IBatch with
member f.Connection
with get() = new Devart.Data.Oracle.OracleConnection()
and set value = ()
我得到的错误是:
此表达式应具有类型IDbConnection,但此处的类型为Devart.Data.Oracle.OracleConnection
答案 0 :(得分:8)
F#没有像C#那样实现隐式向下转换,你需要
type public Batch =
interface IBatch with
member f.Connection
with get() = new Devart.Data.Oracle.OracleConnection() :> System.Data.IDbConnection
and set value = ()