使用F#中的out参数调用C#重载方法

时间:2016-06-02 01:38:09

标签: f#

我有以下F#代码来处理Gtk.TreeView事件:

  tree.CursorChanged.Add(fun (e : EventArgs) -> 
      let selection = tree.Selection
      let mutable iter = new TreeIter ()
      if selection.GetSelected(&iter) then
        Console.WriteLine("Path of selected row = {0}", model.GetPath(iter))
      )

selection.GetSelected有两个重载,签名

bool GetSelected(out TreeIter, out ITreeModel)

bool GetSelected(out TreeIter)

阻止我使用this post中描述的元组返回版本:

let selection = tree.Selection
match selection.GetSelected() with
| true, iter -> // success
| _ -> // failure

有没有办法用后一种语法指定我想要的GetSelected重载?

修改 为了澄清这个问题,我知道我想要什么方法签名;我只是不知道如何指定它。例如,我试过这个,但没有用:

let f : (byref<TreeIter> -> bool) = selection.GetSelected
match f() with
| true, iter -> // success
| _ -> // failure

1 个答案:

答案 0 :(得分:6)

我认为

match selection.GetSelected() : bool*_ with
...

应该有用。

相关问题