private static void AboutLSP(MyParentClass myObject) { //LSP Violation if (myObject is MyChild child) { child.ChildPrint(); } else { myObject.Print(); } }
private static void DoSafeCast(object obj) { MyParentClass parent = obj as MyParentClass; if (parent == null) { Console.WriteLine("Cast failed!"); } else { Console.WriteLine("Cast is done!"); parent.Print(); } }