Exemplo n.º 1
0
 public void TestCreateFromObject()
 {
     TestClass obj = new TestClass();
     obj.Value = "XXX";
     Func<object, string> switcher = MethodSwitcher.Create<Func<object, string>>(obj, "Ins");
     var valInt = 10;
     Assert.AreEqual(obj.InstanceMethod(valInt), switcher(valInt));
     var valLong = 10;
     Assert.AreEqual(obj.InstanceMethod(valLong), switcher(valLong));
     var valStr = "10";
     Assert.AreEqual(obj.InstanceMethod(valStr), switcher(valStr));
     var valIntArr = new int[2];
     Assert.AreEqual(obj.InstanceMethod(valIntArr), switcher(valIntArr));
     var valLongArr = new long[2];
     Assert.AreEqual(obj.InstanceMethod(valLongArr), switcher(valLongArr));
     string[] valStrArr = new string[3];
     Assert.AreEqual(obj.InstanceMethod(valStrArr), switcher(valStrArr));
     object valObj = new object();
     Assert.AreEqual(obj.InstanceMethod(valObj), switcher(valObj));
 }