gpt4 book ai didi

.net - 如何在F#中创建.NET兼容事件?

转载 作者:行者123 更新时间:2023-12-04 03:35:26 24 4
gpt4 key购买 nike

我正在尝试发布F#类型的事件,但我希望将其视为C#或VB中的事件。似乎正确的方法曾经是IEvent.create_HandlerEvent,但是最新版本的F#中不存在此函数。那么现在正确的方法是什么?

最佳答案

事件不是我的专长,但是此示例似乎适用于F#1.9.6.16:

namespace EventExample
open System
type MyEventArgs(msg:string) =
inherit EventArgs()
member this.Message = msg

type MyEventDelegate = delegate of obj * MyEventArgs -> unit

type Foo() =
let ev = new Event<MyEventDelegate, MyEventArgs>()

member this.Ping(msg) =
ev.Trigger(this, new MyEventArgs(msg))

[<CLIEvent>]
member this.GotPinged = ev.Publish

也可以看看

http://cs.hubfs.net/forums/thread/10555.aspx

关于.net - 如何在F#中创建.NET兼容事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/904235/

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