예제 #1
0
 private static void AboutLSP(MyParentClass myObject)
 {
     //LSP Violation
     if (myObject is MyChild child)
     {
         child.ChildPrint();
     }
     else
     {
         myObject.Print();
     }
 }
예제 #2
0
        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();
            }
        }