簡體   English   中英

F#接口實現

[英]F# Interface Implementation

假設我在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

F#沒有像C#那樣實現隱式向下轉換,你需要擁有

type public Batch = 
    interface IBatch with
        member f.Connection 
            with get() = new Devart.Data.Oracle.OracleConnection() :> System.Data.IDbConnection
            and set value = ()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM