By on 5/26/2009 8:03 AM ()
You can use the F# "Event" type to create an event. If you want to compile it as a standard C# event declaration, you'll need to use "CLIEvent" attribute (this is new in the latest version). You can also use "DelegateEvent" type if you want to specify the delegate type explicitly (otherwise, F# uses some generic delegate type from FSharp.Core.dll):

namespace FSharpLib

// Declare class for testing, which can be used from C#
type Test() =
  // Declare event with 'EventHandler' delegate
  let evt1 = new DelegateEvent<System.EventHandler>()
  // Deckare event that'll use standard F# generic delegate type
  let evt2 = new Event<System.EventArgs>()

  // Expose the first event as C# event
  member x.Event1 = evt1.Publish
  member x.Foo1() = evt1.Trigger([| box x; box System.EventArgs.Empty |]) // trigger it

  // Expose the second event as C#-compatible event
  member x.Event2 = evt2.Publish
  member x.Foo2() = evt2.Trigger(System.EventArgs.Empty) // trigger it!
By on 5/26/2009 7:38 AM ()
Thanks! That was exactly what I needed.
By on 5/26/2009 1:13 PM ()
Any chance you could post the matching code in C# that hooks up to this event?


By on 9/8/2009 10:00 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper