How would one implement INotifyPropertyChanged for use in an F# type? Thanks!
+1
A:
It's basically the same as in any other language:
open System.ComponentModel
type MyType() =
let ev = new Event<_,_>()
let mutable str = ""
member x.StringProp
with get() = str
and set(str') =
str <- str'
ev.Trigger(x, PropertyChangedEventArgs("StringProp"))
interface INotifyPropertyChanged with
[<CLIEvent>]
member x.PropertyChanged = ev.Publish
kvb
2009-11-08 22:58:25
That is not "basically the same" as other languages :P
Cameron MacFarland
2009-11-08 23:10:15
Thanks,What exactly is the [<CLIEvent>] attribute do? I can't seem to find any the documentation on it.
RodYan
2009-11-08 23:17:00
@RodYan - it affects the compiled form that the event takes; for interop with other .NET languages (and to implement interfaces exposing .NET events), you'll need to apply it to an IEvent value. This causes `add_` and `remove_` methods to be generated, as opposed to actually exposing a property of type `IEvent<_,_>`, as described at http://msdn.microsoft.com/en-us/library/ee370437(VS.100).aspx.
kvb
2009-11-08 23:28:46