Reputation: 7746
I have an F# class library as such:
namespace FsharpTestSystem
open System
open System.IO
open TCLoggerEntity
open TCIQuoteEntity
type TestCallback() =
member this.LoggerOutput() = Logger.Info("F#")
member this.OnQuote(q : TCQuote) = Console.WriteLine(q.ToString())
Adding a reference of this F# assembly into a C# project, I have tested that I can call LoggerOutput fine from C#. However, if I try to have C# event callback execute in F# I get an error on the line below:
From C#:
using FsharpTestSystem;
public delegate void QuoteChangeEvent(TCQuote q);
event QuoteChangeEvent OnQuoteChange;
TestCallback fsts = new TestCallback();
api.MAPI.OnQuoteChange += fsts.OnQuote(); // this doesn't work
fsts.LoggerOutput(); // This works fine
Upvotes: 2
Views: 134
Reputation: 44316
you are invoking your method, which would try and use whatever OnQuote returned as the event handler.
OnQuote is the event handler, so try :-
api.MAPI.OnQuoteChange += fsts.OnQuote;
Upvotes: 5