Esempio n. 1
0
            /// <summary>
            /// Creates a new <see cref="Subscriber"/> for the specified type of the source object.
            /// </summary>
            /// <param name="type">The type of the source object.</param>
            /// <param name="observer">The underlying observer.</param>
            /// <returns>A <see cref="Subscriber"/> for the <paramref name="type"/>.</returns>
            private static Subscriber Create(Type type, PropertyObserver observer)
            {
                Subscriber subscriber = (Subscriber)Activator.CreateInstance(typeof(TSubscriber <>).MakeGenericType(type), true);

                subscriber.observer = observer;

                return(subscriber);
            }
Esempio n. 2
0
            /// <summary>
            /// Creates a new <see cref="Subscriber"/> for the specified type of the source object.
            /// </summary>
            /// <typeparam name="T">The type of the source object.</typeparam>
            /// <param name="observer">The underlying observer.</param>
            /// <returns>A <see cref="Subscriber"/> for the <typeparamref name="T"/>.</returns>
            private static Subscriber Create <T>(PropertyObserver observer) where T : class, INotifyPropertyChanged
            {
                Subscriber subscriber = new TSubscriber <T>();

                subscriber.observer = observer;

                return(subscriber);
            }
Esempio n. 3
0
            /// <summary>
            /// Creates a new <see cref="Subscriber"/> for the specified source object.
            /// </summary>
            /// <typeparam name="T">The type of the source object.</typeparam>
            /// <param name="source">The source object.</param>
            /// <param name="observer">The underlying observer.</param>
            /// <returns>A <see cref="Subscriber"/> for the <paramref name="source"/>.</returns>
            internal static Subscriber Create <T>(T source, PropertyObserver observer) where T : class, INotifyPropertyChanged
            {
                Type type = source.GetType();

                if (type == typeof(T))
                {
                    return(Create <T>(observer));
                }

                return(Create(type, observer));
            }
Esempio n. 4
0
        public void Test_01()
        {
            PropertyObserver observer = new PropertyObserver();

            try
            {
                ISubscriber <Sample> observe = observer.Observe <Sample>(null);

                Assert.Fail();
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual("source", e.ParamName);
            }
        }
Esempio n. 5
0
        public void Test_14()
        {
            Sample sample = new Sample();

            PropertyObserver observer = new PropertyObserver();

            ISubscriber <Sample> observe = observer.Observe(sample);

            observe.Subscribe(nameof(Sample.Prop1), Fail);

            ISubscriber <Sample> subscriber = observe.Unsubscribe(nameof(Sample.Prop1), Fail);

            sample.Prop1 = "Value";
            sample.Prop2 = "Value";

            Assert.AreSame(observe, subscriber);
Esempio n. 6
0
        public void Test_04()
        {
            Sample sample = new Sample();

            PropertyObserver observer = new PropertyObserver();

            ISubscriber <Sample> observe = observer.Observe(sample);

            int count = 0;

            ISubscriber <Sample> subscriber = observe.Subscribe(nameof(Sample.Prop1), () => { count++; });

            sample.Update();

            Assert.AreEqual(1, count);
            Assert.AreSame(observe, subscriber);
        }
Esempio n. 7
0
        public void Test_05()
        {
            Sample sample = new Sample();

            PropertyObserver observer = new PropertyObserver();

            ISubscriber <Sample> observe = observer.Observe(sample);

            List <Sample> list = new List <Sample>();

            ISubscriber <Sample> subscriber = observe.Subscribe(nameof(Sample.Prop1), s => { list.Add(s); });

            sample.Update();

            Assert.AreEqual(1, list.Count);
            Assert.AreSame(sample, list[0]);
            Assert.AreSame(observe, subscriber);
        }
Esempio n. 8
0
        public void Test_12()
        {
            Sample sample = new Sample();

            PropertyObserver observer = new PropertyObserver();

            ISubscriber <Sample> observe = observer.Observe(sample);

            int count = 0;

            ISubscriber <Sample> subscriber = observe.Subscribe(() => { count++; });

            sample.Prop1 = "Value";
            sample.Prop2 = "Value";

            Assert.AreEqual(2, count);
            Assert.AreSame(observe, subscriber);
        }
Esempio n. 9
0
        public void Test_09()
        {
            Sample sample = new Sample();

            PropertyObserver observer = new PropertyObserver();

            ISubscriber <Sample> observe = observer.Observe(sample);

            List <Sample> list = new List <Sample>();

            ISubscriber <Sample> subscriber = observe.Subscribe(null, s => { list.Add(s); });

            sample.Prop1 = "Value";
            sample.Prop2 = "Value";

            Assert.AreEqual(0, list.Count);
            Assert.AreSame(observe, subscriber);
        }