using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; interface IFoo { Type Foo(); } interface IBar { Type Bar1

(); Type Bar2(); void Bar3(out Type t, out Type u); } class FooBar : IFoo, IBar { public Type Foo() { Console.WriteLine("At IFoo::Foo: TypeOf(T) = {0}", typeof(T)); return typeof(T); } public Type Bar1

() { Console.WriteLine("At IBar::Foo

: TypeOf(P) = {0}", typeof(P)); return typeof(P); } public Type Bar2() { Console.WriteLine("At IBar::Bar2: TypeOf(K) = {0}", typeof(K)); return typeof(K); } public void Bar3(out Type t, out Type u) { Console.WriteLine("At IBar::Bar3: TypeOf(P) = {0}, TypeOf(K) = {1}", typeof(P), typeof(K)); t = typeof(P); u = typeof(K); } } class Program { static int Main(string[] args) { FooBar fooBar = new FooBar(); IFoo foo = (IFoo) fooBar; IBar bar = (IBar) fooBar; Console.WriteLine("Calling IFoo.Foo on FooBar - expecting IFoo::Foo() returning typeof(string)"); Test.Assert(foo.Foo() == typeof(string), "Calling IFoo.Foo on FooBar"); Console.WriteLine("Calling IBar.Bar1 on FooBar - expecting bar.Bar1() returning typeof(string)"); Test.Assert(bar.Bar1() == typeof(string), "Calling IBar.Bar1 on FooBar"); Console.WriteLine("Calling IBar.Bar2 on FooBar - expecting bar.Bar2() returning typeof(string[])"); Test.Assert(bar.Bar2() == typeof(string[]), "Calling IBar.Bar2 on FooBar"); Type p, k; Console.WriteLine("Calling IBar.Bar3 - expecting bar.Bar3() returning typeof(string), typeof(string[])"); bar.Bar3(out p, out k); Test.Assert(p == typeof(string) && k == typeof(string[]), "Calling IBar.Bar3"); return Test.Ret(); } } class Test { private static bool Pass = true; public static int Ret() { return Pass ? 100 : 101; } public static void Assert(bool cond, string msg) { if (cond) { Console.WriteLine("PASS"); } else { Console.WriteLine("FAIL: " + msg); Pass = false; } } }