如何在F#.NET兼容的事件? [英] How to create .NET-compatible events in F#?
本文介绍了如何在F#.NET兼容的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从发布的F#类型的事件,但我希望它被看作是从C#或VB的事件。看来,做正确的方式,它曾经是IEvent.create_HandlerEvent,但是这个功能不能在F#的最新版本存在。那么,什么是现在就这样做了正确的方法是什么?
I am trying to publish an event from an F# type, but I want it to be seen as an event from C# or VB. It seems that the correct way to do it used to be IEvent.create_HandlerEvent, but this function doesn't exist in the newest version of F#. So what is the correct way to do it now?
推荐答案
事件是不是我的专长,但这个例子似乎工作在F#1.9.6.16:
Events are not my forte, but this example seems to work on 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
另请参见
<一个href="http://cs.hubfs.net/forums/thread/10555.aspx">http://cs.hubfs.net/forums/thread/10555.aspx
这篇关于如何在F#.NET兼容的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文