C# 什么是F#的标准类型事件?

C# 什么是F#的标准类型事件?,c#,.net-core,f#,rabbitmq,event-handling,C#,.net Core,F#,Rabbitmq,Event Handling,我正在尝试从F订阅/取消订阅C#made(在RabbitMQ客户端库中): 已接收到公共事件AsyncEventHandler; public委托任务AsyncEventHandler(对象发送方,TEvent@event),其中TEvent:EventArgs; 我通过以下方式订阅了该活动: 让subscribeAsync(通道:IModel)交换回调= 让使用者=AsyncEventingBasicConsumer(通道) 已收到consumer.add_(AsyncEventHan

我正在尝试从F订阅/取消订阅C#made(在RabbitMQ客户端库中):

已接收到公共事件AsyncEventHandler;

public委托任务AsyncEventHandler(对象发送方,TEvent@event),其中TEvent:EventArgs;
我通过以下方式订阅了该活动:

让subscribeAsync(通道:IModel)交换回调=
让使用者=AsyncEventingBasicConsumer(通道)
已收到consumer.add_(AsyncEventHandler(有趣的发送者参数->任务.CompletedTask))
// ...
话虽如此,我想知道为什么下面的代码无法编译:

让subscribeAsync(通道:IModel)交换回调=
让使用者=AsyncEventingBasicConsumer(通道)
consumer.Received.AddHandler(AsyncEventHandler(有趣的发送者参数->任务.CompletedTask))
// ...
因为我得到以下错误:

Program.fs(10, 14): [FS1091] The event 'Received' has a non-standard type. If this event is declared in another CLI language, you may need to access this event using the explicit add_Received and remove_Received methods for the event. If this event is declared in F#, make the type of the event an instantiation of either 'IDelegateEvent<_>' or 'IEvent<_,_>'.
Program.fs(10,14):[FS1091]事件“已接收”具有非标准类型。如果此事件是用另一种CLI语言声明的,则可能需要使用事件的显式add_Received和remove_Received方法访问此事件。如果此事件是在F#中声明的,则将事件类型设置为“IDelegateEvent”或“IEvent”的实例化。
我检查了,但看不到对F#的标准事件类型的任何引用。

F#将把.NET事件公开为
IEvent
IDelegateEvent
类型的值,具体取决于事件声明和委托类型。这只能对具有一些基本公共结构的事件执行-当F#无法执行此操作时,它会将事件的基础
add
remove
操作公开为可直接调用的方法

我不确定什么是“标准事件类型”的规则。但是,您可以从以下方面获得一些提示:

因此,我猜“Statnard事件类型”需要:

  • 至少有一个参数
  • 第一个参数的类型必须为
    object
  • 没有
    byref
    参数

有道理,我开始深入研究编译器,但花了一段时间才找到正确的位置。谢谢你,托马斯!
let TryDestStandardDelegateType (infoReader: InfoReader) m ad delTy =
    let g = infoReader.g
    let (SigOfFunctionForDelegate(_, compiledViewOfDelArgTys, delRetTy, _)) =
        GetSigOfFunctionForDelegate infoReader delTy m ad
    match compiledViewOfDelArgTys with 
    | senderTy :: argTys when (isObjTy g senderTy) && 
         not (List.exists (isByrefTy g) argTys)  -> Some(mkRefTupledTy g argTys, delRetTy)
    | _ -> None