在 F# 中使用 C# 库

本文关键字: | 更新日期: 2023-09-27 18:33:23

我正在尝试通过盈透证券的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# 库。

在 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>用于在文件顶部声明的模块或命名空间中声明子模块。

相关文章:
  • 没有找到相关文章