Example #1
0
        private static void RunOnserverPattern()
        {
            Market market = new Market();

            market.PropertyChanged += (sender, eventArgs) =>
            {
                if (eventArgs.PropertyName == "Volatility")
                {
                    Console.WriteLine($"{eventArgs.PropertyName} has changed");
                }
            };

            market.PriceAdded += (sender, f) =>
            {
                Console.WriteLine($"We got a price {f}");
            };


            market.Bids.ListChanged += (sender, eventArgs) =>
            {
                if (eventArgs.ListChangedType == ListChangedType.ItemAdded)
                {
                    float bid = ((BindingList <float>)sender)[eventArgs.NewIndex];
                    Console.WriteLine($"Recevied bid with offer price of {bid}");
                }
            };


            market.AddPrice(123);
            market.Volatility = 2;
            market.Bids.Add(2000);
        }
        public static void BindingListDemo()
        {
            var market = new Market();

            market.Prices.ListChanged += (sender, eventArgs) =>             // Subscribe
            {
                if (eventArgs.ListChangedType == ListChangedType.ItemAdded)
                {
                    WriteLine($"Added price {((BindingList<float>)sender)[eventArgs.NewIndex]}");
                }
            };
            market.AddPrice(123);

            // the BindingList has some additional flags that allows extra customization to some degree
            market.Prices.AllowNew = false;
            market.AddPrice(222);
        }