gpt4 book ai didi

excel - 接口(interface)和扩展ApplicationClass

转载 作者:行者123 更新时间:2023-12-03 02:50:16 25 4
gpt4 key购买 nike

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

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

我没有意识到的是,我会收到以下错误“所有实现的接口(interface)都应该在类型的初始声明中声明”。

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

最佳答案

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

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

关于excel - 接口(interface)和扩展ApplicationClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21230188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com