我在 F# 中创建了一个实现 IDisposable 接口的类。该类已正确清理,并且 use 关键字能够访问 Dispose 方法。我有第二个用例,我需要显式调用 Dispose 方法,但无法在下面的示例中调用。似乎 Dipose 方法在类中不可用。
open System
type Foo() = class
do
()
interface IDisposable with
member x.Dispose() =
printfn "Disposing"
end
let test() =
// This usage is ok, and correctly runs Dispose()
use f = new Foo()
let f2 = new Foo()
// The Dispose method isn't available and this code is not valid
// "The field , constructor or member Dispose is not defined."
f2.Dispose()
test()