簡體   English   中英

在f#中使用c#庫

[英]use c# library in f#

我正在嘗試通過其C#API連接到盈透證券。 作為練習,我正在嘗試使用F#開發客戶。

這是我所做的:

  1. 我已經在Visual Studio中導入了CSharpAPI項目。 CSharpAPI定義了IBApi命名空間
  2. 我在解決方案中創建了一個新的F#項目。 該項目將主持我的實施
  3. 我在.fs文件中創建了一個新模塊,如下所示:

     open IBApi module ibConnectivity = type IBclient = interface EWrapper with member this.connectionClosed() = printfn "connection has been closed" member this.currentTime time = printfn "server time: %i" time .... 

我收到以下錯誤消息:

錯誤1庫或多文件應用程序中的文件必須以名稱空間或模塊聲明開頭,例如'namespace SomeNamespace.SubNamespace'或'module SomeNamespace.SomeModule'

我已經到處搜尋解決方案。 我是一個完整的菜鳥。 一些帖子引用了F#文件的順序,但是在這種情況下,我正在使用C#庫。

這意味着您的文件必須以namespacemodule聲明開頭。 像這樣:

module ibConnectivity

open IBApi

type IBclient =
    interface EWrapper with
    member this.connectionClosed() = printfn "connection has been closed"
    member this.currentTime time = printfn "server time: %i" time

語法module Name = <indented declarations>用於聲明在文件頂部聲明的模塊或名稱空間中的子模塊。

暫無
暫無

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

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