Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace System
- {
- public static class DelegateEx
- {
- public static IObservable<IEvent<TEventArgs>> AsObservable<TEventArgs>(this EventHandler<TEventArgs> @event) where TEventArgs : EventArgs
- {
- return Observable.FromEvent<TEventArgs>(handler => @event += handler, handler => @event -= handler);
- }
- }
- public class Program
- {
- public static EventHandler<EventArgs> SomeEvent;
- static void Main()
- {
- var synthesis = new System.Speech.Synthesis.SpeechSynthesizer();
- SomeEvent.AsObservable().Subscribe(args => synthesis.Speak(args.Sender.ToString()));
- synthesis.Speak(SomeEvent == null ? "SomeEvent is null." : "SomeEvent is not null.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement