示例#1
0
 public void TestDemo2Reflection()
 {
     object reflectionCalc = new Calculator();
     var calcType = reflectionCalc.GetType();
     object res = calcType.InvokeMember(
         "Add",
         BindingFlags.InvokeMethod,
         null,
         Activator.CreateInstance(calcType),
         new object[] {10, 20});
     int sum = Convert.ToInt32(res);
     Assert.AreEqual(30, sum);
 }
示例#2
0
 public void TestDemo2Dynamic()
 {
     dynamic calc = new Calculator();
     Assert.AreEqual(30, calc.Add(10, 20));
 }
示例#3
0
 public void TestDemo2Itf()
 {
     ICalc calc = new Calculator();
     Assert.AreEqual(30, calc.Add(10, 20));
 }
示例#4
0
 public void TestDemo2Object()
 {
     object calc = new Calculator();
     //Assert.AreEqual(30, calc.Add(10, 20));
 }
示例#5
0
 public void TestDemo2Static()
 {
     Calculator calc = new Calculator();
     Assert.AreEqual(30, calc.Add(10, 20));
 }