static void Main() { { TestLogger.Log("Testing basic interface methods..."); ISimple s1 = new CSimple(); s1.S(); ISimple s2 = new SSimple(); s2.S(); ISimple s3 = new CDerived1(); s3.S(); ISimple s4 = new CDerived2(); s4.S(); ISimple s5 = new CDerived3(); s5.S(); } { TestLogger.Log("Testing virtuals..."); object c = new CChild(); var ia = c as IA; var d = c as Dummy; if (d != null) { TestLogger.Log("Invalid casting"); } TestLogger.Log(5.ToString()); TestLogger.Log(ia.A()); TestLogger.Log(((CA)c).Virtual()); TestLogger.Log(((CChild)c).VirtualDontOverride()); TestLogger.Log(((IB)c).A()); TestLogger.Log(((IAB)c).B()); TestLogger.Log((new CGrandChild()).Virtual()); // TestLogger.Log(((IAB)c).A()); // ambiguous at compile-time } { TestLogger.Log("Testing constrained call on 'naked' type parameter..."); var cic = new ConstrainedInterface <CSimple>(); cic.M(new CSimple()); var cis = new ConstrainedInterface <SSimple>(); cis.M(new SSimple()); var cc = new ConstrainedClass <CSimple>(); cc.M(new CSimple()); var cs = new ConstrainedStruct <SSimple>(); cs.M(new SSimple()); var kc = new KnownClass(); kc.M(new CSimple()); var ks = new KnownStruct(); ks.M(new SSimple()); } { TestLogger.Log("Testing implicit interface implementations..."); var b = new BaseImplicit(); var d = new DerivedImplicit(); ((IImplicit)b).M(1); ((IImplicit)b).M(false); ((IImplicit)b).M("three"); ((IImplicit)b).M(4.0f); ((IImplicit)d).M(2); ((IImplicit)d).M(true); ((IImplicit)d).M("five"); ((IImplicit)d).M(6.0f); } }
public void M(CSimple t) { t.S(); TestLogger.Log(t.ToString()); TestLogger.Log(t.GetType().Name); }