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