我正在尝试在F#中编写一个模块,通过提取行,列等以及类型转换等方式,可以更轻松地使用Excel。我想要做的第一件事就是扩展各种类/类型以实现IDisposable
接口。我试着写下面的内容
type Excel.ApplicationClass with
interface IDisposable with
member this.Dispose() =
this.excel.Quit()
Marshal.ReleaseComObject(this.excel) |> ignore
我不知道的是,我会得到以下错误“所有实现的接口都应该在类型的初始声明中声明。”
我的问题如下:由于我不允许使用界面扩展类型 - 我还能做什么?
答案 0 :(得分:3)
如果从基类继承它可以工作,就像这样
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