admin管理员组

文章数量:1323730

In a C# class I have the following definition

public event Action<Unit> Output1;

This type of definition is required by a third party application (TPA). This application imports a DLL containing classes with definitions like the above and expose these fields graphically.

I'd like to define these classes in F#. So I have tried the official equivalent

let output1 = Event<Unit>()
[<CLIEvent>]
member __.Output1 = output1.Publish

but the TPA application does not recognize it. I guess TPA is using reflection, so I inspected the C# and F# built DLL in ILSpy

public event Action<Unit> Output1;
[CLIEvent]
public event FSharpHandler<Unit> Output1
{
    add
    {
        if (init@16 < 1)
        {
            LanguagePrimitives.IntrinsicFunctions.FailInit();
        }
        output1.Publish.AddHandler(value);
    }
    remove
    {
        if (init@16 < 1)
        {
            LanguagePrimitives.IntrinsicFunctions.FailInit();
        }
        output1.Publish.RemoveHandler(value);
    }
}

So the reason why TPA does not recognize the F# definition is this difference. Hence my question:

Is there a way to define the member in F# so that it is built EXACTLY like the C# one?

本文标签: Defining C events in FStack Overflow