gpt4 book ai didi

c# - 从 C# 到 F# 的回调

转载 作者:行者123 更新时间:2023-12-03 20:30:27 25 4
gpt4 key购买 nike

我有一个 F# 类库:

namespace FsharpTestSystem

open System
open System.IO

open TCLoggerEntity
open TCIQuoteEntity

type TestCallback() =
member this.LoggerOutput() = Logger.Info("F#")
member this.OnQuote(q : TCQuote) = Console.WriteLine(q.ToString())

将此 F# 程序集的引用添加到 C# 项目中,我已经测试过可以从 C# 正常调用 LoggerOutput。但是,如果我尝试在 F# 中执行 C# 事件回调,则会在下面的行中收到错误:

来自 C#:

using FsharpTestSystem;

public delegate void QuoteChangeEvent(TCQuote q);
event QuoteChangeEvent OnQuoteChange;

TestCallback fsts = new TestCallback();
api.MAPI.OnQuoteChange += fsts.OnQuote(); // this doesn't work

fsts.LoggerOutput(); // This works fine

最佳答案

您正在调用您的方法,该方法将尝试使用 OnQuote 返回的任何内容作为事件处理程序。

OnQuote 是事件处理程序,因此请尝试:-

api.MAPI.OnQuoteChange += fsts.OnQuote;

关于c# - 从 C# 到 F# 的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606329/

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