Пример #1
0
        public void FromEventPattern()
        {
            var test = new EventTestesr();

            {
                var isRaised = false;
                var d = Observable.FromEventPattern<EventHandler, EventArgs>(
                    h => h.Invoke,
                    h => test.Event1 += h, h => test.Event1 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(1);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(1);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>(
                    h => h.Invoke,
                    h => test.Event2 += h, h => test.Event2 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(2);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(2);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEventPattern<MyEventHandler, MyEventArgs>(
                    h => h.Invoke,
                    h => test.Event3 += h, h => test.Event3 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(3);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(3);
                isRaised.IsFalse();
            }
        }
Пример #2
0
        static void EventAotCheck()
        {
            var test = new EventTestesr();

            {
                var isRaised = false;
                var d        = Observable.FromEventPattern <EventHandler, EventArgs>(
                    h => h.Invoke,
                    h => test.Event1                   += h, h => test.Event1 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(1);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(1);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEventPattern <EventHandler <MyEventArgs>, MyEventArgs>(
                    h => h.Invoke,
                    h => test.Event2                   += h, h => test.Event2 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(2);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(2);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEventPattern <MyEventHandler, MyEventArgs>(
                    h => h.Invoke,
                    h => test.Event3                   += h, h => test.Event3 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(3);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(3);
                Console.WriteLine(isRaised == false);
            }
        }
Пример #3
0
        public void FromEventPattern()
        {
            var test = new EventTestesr();

            {
                var isRaised = false;
                var d        = UtyRx.Observable.FromEventPattern <EventHandler, EventArgs>(
                    h => h.Invoke,
                    h => test.Event1                   += h, h => test.Event1 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(1);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(1);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d        = UtyRx.Observable.FromEventPattern <EventHandler <MyEventArgs>, MyEventArgs>(
                    h => h.Invoke,
                    h => test.Event2                   += h, h => test.Event2 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(2);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(2);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d        = UtyRx.Observable.FromEventPattern <MyEventHandler, MyEventArgs>(
                    h => h.Invoke,
                    h => test.Event3                   += h, h => test.Event3 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(3);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(3);
                isRaised.IsFalse();
            }
        }
Пример #4
0
        public void FromEvent()
        {
            var test = new EventTestesr();

            {
                var isRaised = false;
                var d = Observable.FromEvent<EventHandler, EventArgs>(
                    h => (sender, e) => h.Invoke(e),
                    h => test.Event1 += h, h => test.Event1 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(1);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(1);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEvent<EventHandler<MyEventArgs>, MyEventArgs>(
                    h => (sender, e) => h.Invoke(e),
                    h => test.Event2 += h, h => test.Event2 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(2);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(2);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEvent<MyEventHandler, MyEventArgs>(
                    h => (sender, e) => h.Invoke(e),
                    h => test.Event3 += h, h => test.Event3 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(3);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(3);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEvent<Action, Unit>(
                    h => () => h(Unit.Default),
                    h => test.Event4 += h, h => test.Event4 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(4);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(4);
                isRaised.IsFalse();
            }

            // shortcut
            {
                var isRaised = false;
                var d = Observable.FromEvent(
                    h => test.Event4 += h, h => test.Event4 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(4);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(4);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEvent<Action<int>, int>(
                    h => h,
                    h => test.Event5 += h, h => test.Event5 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(5);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(5);
                isRaised.IsFalse();
            }

            // shortcut
            {
                var isRaised = false;
                var d = Observable.FromEvent<int>(
                    h => test.Event5 += h, h => test.Event5 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(5);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(5);
                isRaised.IsFalse();
            }

            {
                var isRaised = false;
                var d = Observable.FromEvent<Action<int, string>, Tuple<int, string>>(
                    h => (x, y) => h(Tuple.Create(x, y)),
                    h => test.Event6 += h, h => test.Event6 -= h)
                    .Subscribe(x => isRaised = true);
                test.Fire(6);
                isRaised.IsTrue();
                isRaised = false;
                d.Dispose();
                test.Fire(6);
                isRaised.IsFalse();
            }
        }
Пример #5
0
        static void EventAotCheck2()
        {
            var test = new EventTestesr();

            {
                var isRaised = false;
                var d        = Observable.FromEvent <EventHandler, EventArgs>(
                    h => (sender, e) => h.Invoke(e),
                    h => test.Event1                   += h, h => test.Event1 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(1);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(1);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEvent <EventHandler <MyEventArgs>, MyEventArgs>(
                    h => (sender, e) => h.Invoke(e),
                    h => test.Event2                   += h, h => test.Event2 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(2);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(2);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEvent <MyEventHandler, MyEventArgs>(
                    h => (sender, e) => h.Invoke(e),
                    h => test.Event3                   += h, h => test.Event3 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(3);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(3);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEvent <Action, Unit>(
                    h => () => h(Unit.Default),
                    h => test.Event4                   += h, h => test.Event4 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(4);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(4);
                Console.WriteLine(isRaised == false);
            }

            // shortcut
            {
                var isRaised = false;
                var d        = Observable.FromEvent(
                    h => test.Event4                   += h, h => test.Event4 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(4);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(4);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEvent <Action <int>, int>(
                    h => h,
                    h => test.Event5                   += h, h => test.Event5 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(5);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(5);
                Console.WriteLine(isRaised == false);
            }

            // shortcut
            {
                var isRaised = false;
                var d        = Observable.FromEvent <int>(
                    h => test.Event5                   += h, h => test.Event5 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(5);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(5);
                Console.WriteLine(isRaised == false);
            }

            {
                var isRaised = false;
                var d        = Observable.FromEvent <Action <int, string>, Tuple <int, string> >(
                    h => (x, y) => h(Tuple.Create(x, y)),
                    h => test.Event6                   += h, h => test.Event6 -= h)
                               .Subscribe(x => isRaised = true);
                test.Fire(6);
                Console.WriteLine(isRaised);
                isRaised = false;
                d.Dispose();
                test.Fire(6);
                Console.WriteLine(isRaised == false);
            }
        }
Пример #6
0
 public void FromEventPattern()
 {
     SetScehdulerForImport();
     var test = new EventTestesr();
     {
         var isRaised = false;
         var d = Observable.FromEventPattern<EventHandler, EventArgs>(
             h => h.Invoke,
             h => test.Event1 += h, h => test.Event1 -= h)
             .Subscribe(x => isRaised = true);
         test.Fire(1);
         isRaised.IsTrue();
         isRaised = false;
         d.Dispose();
         test.Fire(1);
         isRaised.IsFalse();
     }
     {
         var isRaised = false;
         var d = Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>(
             h => h.Invoke,
             h => test.Event2 += h, h => test.Event2 -= h)
             .Subscribe(x => isRaised = true);
         test.Fire(2);
         isRaised.IsTrue();
         isRaised = false;
         d.Dispose();
         test.Fire(2);
         isRaised.IsFalse();
     }
     {
         var isRaised = false;
         var d = Observable.FromEventPattern<MyEventHandler, MyEventArgs>(
             h => h.Invoke,
             h => test.Event3 += h, h => test.Event3 -= h)
             .Subscribe(x => isRaised = true);
         test.Fire(3);
         isRaised.IsTrue();
         isRaised = false;
         d.Dispose();
         test.Fire(3);
         isRaised.IsFalse();
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }