为什么我可以将两个参数传递给Event类

时间:2015-03-03 09:29:18

标签: f#

当我在f#

中查看事件类的定义时
type Event<'T> =
 class
  new Event : unit -> Event<'T>
  member this.Trigger : 'T -> unit
  member this.Publish :  IEvent<'T>
 end

我只能在事件类上传递一种类型,如

let nameChanged = new Event<unit>()

但是我也看到了一些样本,它传递了两个变量,比如

let propertyChanged = Event<PropertyChangedEventHandler, PropertyChangedEventArgs>()

怎么可能呢?

当我实现像

这样的界面时
module SapHandler

open SAP.Middleware.Connector

type Connector() =

    let configurationChanged = Event<RfcDestinationManager.ConfigurationChangeHandler, RfcConfigurationEventArgs>()  

    interface IDestinationConfiguration with
        member self.ChangeEventsSupported() =
            false
        [<CLIEvent>]
        member self.ConfigurationChanged = configurationChanged.Publish

编译器抱怨:

The type 'RfcDestinationManager.ConfigurationChangeHandler' has a non-standard delegate type  

为什么?
委托类型的定义是: enter image description here

1 个答案:

答案 0 :(得分:1)

这是可能的,因为还有另一个class too

type Event<'Delegate,'Args (requires delegate)> =
 class
  new Event : unit -> Event<'Delegate,'Args>
  member this.Trigger : obj * 'Args -> unit
  member this.Publish :  IEvent<'Delegate,'Args>
 end

您收到该错误,因为您的事件委托可能缺少.net中标准的第一个object sender参数。您可以使用Control.DelegateEvent<'Delegate>来解决此问题

let propertyChanged = DelegateEvent<RfcDestinationManager.ConfigurationChangeHandler>()