2013-10-22 145 views
4

讓說我有在C#此接口,要實現它在F#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

回答

7

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

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

啊。我知道這是我錯過的一個簡單的語法細節。謝謝!將在10分鐘內接受你的答案 – Filip