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(); }
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"); }