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

标签 .net events f#

我正在尝试发布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/

相关文章:

c# - NHibernate firebird 错误 - 索引超出范围

c# - 用于捕获撰写邮件事件的 outlook 插件

c# - 将按钮的事件订阅到自定义控件中

c# - C# 中事件和更改标记之间的区别

csv - 在 F# 中向 CsvProvider 类型添加新成员

f# - 如何使用GitVersion环境变量

c# - Async TCP Server 代码示例分析

asp.net - 在 web.config 中使用 TNS_ADMIN 的相对路径

c# - 使用图形的图形布局#

f# - 将 Pipe Forward 与嵌套序列一起使用