How can I get an IObservable<T> in Rx from a "non-standard" event?
- by Dan Tao
Here's what I mean. Suppose I'm working with an API that exposes events, but these events do not follow the standard EventHandler or EventHandler<TEventArgs> signature. One event might look like this, for instance:
Public Event Update(ByVal sender As BaseSubscription, ByVal e As BaseEvent)
Now, typically, if I want to get an IObservable<TEventArgs> from an event, I can just do this:
Dim updates = Observable.FromEvent(Of UpdateEventArgs)( _
target:=updateSource, _
eventName:="Update" _
)
But this doesn't work, because the Update event is not an EventHandler<UpdateEventArgs> -- in fact, there is no UpdateEventArgs -- it's basically just its own thing.
Obviously, I could define my own class deriving from EventArgs (i.e., UpdateEventArgs), write another class to wrap the object providing the Update event, give the wrapper class its own Update event that is an EventHandler<UpdateEventArgs>, and get an IObservable<UpdateEventArgs> from that. But that's an annoying amount of work.
Is there some way to create an IObservable<[something]> from a "non-standard" event like this, or am I out of luck?