Пример #1
0
        private static void LSP()
        {
            WriteHeading("LSP");

            WidgetBase widget = new NotLspWidget();

            WidgetBase[] widgetRelatives = widget.Relatives();

            try
            {
                //try to put some other WidgetBase to the array
                widgetRelatives[0] = new LspWidget();
            }
            catch (ArrayTypeMismatchException)
            {
                Console.WriteLine("ArrayTypeMismatchException handled");
            }

            WidgetBase w = new LspWidget();

            WidgetBase[] relatives = w.Relatives();

            //try to put some other WidgetBase to the array
            relatives[0] = new NotLspWidget();
        }
Пример #2
0
        public void LspCovariance_Works()
        {
            WidgetBase w = new LspWidget();

            WidgetBase[] relatives = w.Relatives();

            //try to put some other WidgetBase to the array
            relatives[0] = new NotLspWidget();
            Assert.IsTrue(true);
        }
Пример #3
0
        public void LspCovariance_ThrowException()
        {
            WidgetBase w = new NotLspWidget();

            WidgetBase[] relatives = w.Relatives();

            //try to put some other WidgetBase to the array
            relatives[0] = new LspWidget();

            Assert.Fail("ArrayTypeMismatchException exception should have been thrown");
        }