public void TestAsFunction() { using (CaptureConsole) { var d = new DynInst(); var t = d.As <Two>(); t(); var p = new { Two = new Func <bool>(() => { Console.WriteLine("In Func<bool> for Two!"); return(true); }) }; var q = p.As <Two>(); q(); var z = new { }; // this creates a dummy function now. var tz = z.As <Two>(); tz(); Func <bool> fTwo = new Func <bool>(() => { Console.WriteLine("In fTwo"); return(true); }); fTwo.As <Two>()(); Assert.Throws <Exception>(() => { Func <string> fThree = new Func <string>(() => { Console.WriteLine("In fThree"); return("true"); }); fThree.As <Two>()(); }); } }
public void TestAsFunction() { using (CaptureConsole) { var d = new DynInst(); var t = d.As<Two>(); t(); var p = new { Two = new Func<bool>(() => { Console.WriteLine("In Func<bool> for Two!"); return true; }) }; var q = p.As<Two>(); q(); var z = new { }; // this creates a dummy function now. var tz = z.As<Two>(); tz(); Func<bool> fTwo = new Func<bool>(() => { Console.WriteLine("In fTwo"); return true; }); fTwo.As<Two>()(); Assert.Throws<Exception>(() => { Func<string> fThree = new Func<string>(() => { Console.WriteLine("In fThree"); return "true"; }); fThree.As<Two>()(); }); } }