【问题标题】:Interfacing and extending ApplicationClass接口和扩展 ApplicationClass
【发布时间】:2014-01-20 09:21:55
【问题描述】:

我正在尝试用 F# 编写一个模块,通过提取行、列等以及类型转换等,使其更容易使用 Excel。我想做的第一件事就是扩展各种类/类型来实现IDisposable 接口。我试图写类似下面的东西

type Excel.ApplicationClass with
    interface IDisposable with
        member this.Dispose() =
            this.excel.Quit()
            Marshal.ReleaseComObject(this.excel) |> ignore

我不知道的是,我会收到以下错误“所有实现的接口都应该在类型的初始声明中声明”。

我的问题如下:由于我不允许使用接口扩展类型 - 我还能做什么?

【问题讨论】:

  • 很容易想到的解决方案是在 Excel 互操作上编写一个包装器。
  • 我也是这么想的。但我宁愿避免它,让它更易于使用。

标签: excel f# office-interop excel-interop


【解决方案1】:

如果你从基类继承它可以工作,像这样

type myAppClass() =
    inherit Excel.ApplicationClass() //may not be correct signature - you need to match the base constructor
    interface IDisposable with
        member this.Dispose() =
            //function body

【讨论】:

  • 非常感谢!它似乎工作!现在我只需要覆盖几个函数!:)
猜你喜欢
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 2023-04-08
  • 2015-04-01
  • 1970-01-01
相关资源
最近更新 更多