我正在尝试从这篇文章http://www.codeproject.com/Articles/35532/C-COM-Object-for-Use-In-JavaScript-HTML-Including翻译成 F# 代码
我偶然发现了这条线:
public delegate void MyFirstEventHandler(string args);
public event MyFirstEventHandler MyFirstEvent;
我试图在 F# 中将其翻译为:
type MyFirstEventHandler = delegate of string -> unit
type MyFsComComponent () =
let my_event = new Event<MyFirstEventHandler,string> ()
[<CLIEvent>]
member x.MyFirstEvent = my_event.Publish
我得到:'MyFirstEventHandler' 有一个非标准委托
我可以编译:
type MyFirstEventHandler = delegate of obj*string -> unit
但这不是 COM 控制所需要的。
在C# 到 F# 类的转换中也提出了这个问题——“公共事件”仍然没有解决方案
解决了。感谢叶花环
type MyFirstEventHandler = delegate of string -> unit
type MyFsComComponent () =
let my_event = new DelegateEvent<MyFirstEventHandler> ()
[<CLIEvent>]
member x.MyFirstEvent = my_event.Publish
成功了。