小编Fal*_*lon的帖子

F#等价的析构函数

我正在翻译一个将非托管库包装到F#的C#类.我遇到了重写后面的析构函数这个看似简单的问题.

class Wrapper {

    // P/Invoke ellided

    private SomeType x;

    public Wrapper() {
        x = new SomeType();
        Begin();
    }

    public ~Wrapper() {
        End();
    }
Run Code Online (Sandbox Code Playgroud)

我现在简化的F#代码如下:

type Wrapper() =
  [<Literal>]
  static let wrappedDll = "Library.dll"

  [<DllImport(wrappedDll , EntryPoint = "Begin")>]
  static extern void Begin()

  [<DllImport(wrappedDll , EntryPoint = "End")>]
  static extern void End()

  let x = new SomeType()

  do
    Begin()
Run Code Online (Sandbox Code Playgroud)

如何修改此F#代码以具有相同的行为?我对F#析构函数的搜索没有出现在我的书籍或网络上.

谢谢.

f# finalizer c#-to-f#

13
推荐指数
2
解决办法
2175
查看次数

标签 统计

c#-to-f# ×1

f# ×1

finalizer ×1