你如何从F#调用接受Action<T>参数的C#函数?

huangapple go评论65阅读模式
英文:

How can I call a C# function that takes an Action<T> from F#?

问题

我需要从F#调用这个函数,并传递一个BinanceRestOptions对象?

英文:

I need to call this function, from a C# lib:

public BinanceRestClient(Action&lt;BinanceRestOptions&gt; optionsDelegate)
  : this((HttpClient) null, (ILoggerFactory) null, optionsDelegate)
{
}

How can I call it from F# and pass a BinanceRestOptions object?

答案1

得分: 2

将匿名函数传递给它,例如:

let bc = BinanceRestClient(fun opts -> ())

或者

let bc = BinanceRestClient(fun opts ->
    opts.SomeProp <- 1
    opts.SomeOtherProp <- "" )
英文:

Pass an anonymous function to it, for example:

let bc = BinanceRestClient(fun opts -&gt; ())

or

let bc = BinanceRestClient(fun opts -&gt;
    opts.SomeProp &lt;- 1
    opts.SomeOtherProp &lt;- &quot;&quot; )

huangapple
  • 本文由 发表于 2023年7月13日 19:15:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定