我尝试使用对象表达式来扩展IDelegateEvent,但是在fsi中有一个错误FS0039:未定义值或构造函数'handler'。
我的代码如下:
type IDelegateEvent<'Del when 'Del:> Delegate> with
member this.Subscribe hanlder =
do this.AddHandler(handler)
{ new IDisposable with
member x.Dispose() =
this.RemoveHandler(handler) }
参考文献是Matthew Podwysocki的博客:http://weblogs.asp.net/podwysocki/archive/2009/08/21/f-first-class-events-creating-and-disposing-handlers.aspx
答案 0 :(得分:3)
由于拼写错误hanlder =