public void TestCallsVirtualMethod() { RefUtilClass1 one = new RefUtilClass1("one"); RefUtilClass1Extends two = new RefUtilClass1Extends("two"); MethodInfo info1 = typeof(RefUtilClass1Extends).GetMethod("CallVirtMethod"); Func <RefUtilClass1, string> d1 = (Func <RefUtilClass1, string>)ReflectionUtil.GetDelegate(info1); Assert.AreEqual("base", d1(one)); Assert.AreEqual("extends", d1(two)); }
public void TestOpenDelegateChild() { RefUtilClass1 one = new RefUtilClass1("one"); RefUtilClass1 two = new RefUtilClass1Extends("two"); MethodInfo info1 = typeof(RefUtilClass1).GetMethod("GetValue"); MethodInfo info2 = typeof(RefUtilClass1Extends).GetMethod("GetValue"); Func <RefUtilClass1, string> d1 = (Func <RefUtilClass1, string>)ReflectionUtil.GetDelegate(info1); Func <RefUtilClass1, string> d2 = (Func <RefUtilClass1, string>)ReflectionUtil.GetDelegate(info2); Assert.AreEqual(d1, d2); Assert.AreEqual("one", d1(one)); Assert.AreEqual("two", d1(two)); }
public void TestOpenDelegateAncestor() { RefUtilClass1 one = new RefUtilClass1("one"); RefUtilClass1Extends two = new RefUtilClass1Extends("two"); RefUtilClass1ExtendsAgain three = new RefUtilClass1ExtendsAgain("three"); MethodInfo info1 = typeof(RefUtilClass1).GetMethod("GetValue"); MethodInfo info2 = typeof(RefUtilClass1Extends).GetMethod("GetValue"); MethodInfo info3 = typeof(RefUtilClass1ExtendsAgain).GetMethod("GetValue"); Func <RefUtilClass1, string> d1 = (Func <RefUtilClass1, string>)ReflectionUtil.GetDelegate(info1); Func <RefUtilClass1, string> d2 = (Func <RefUtilClass1, string>)ReflectionUtil.GetDelegate(info2); Func <RefUtilClass1, string> d3 = (Func <RefUtilClass1, string>)ReflectionUtil.GetDelegate(info3); Assert.AreEqual(d1, d2); Assert.AreEqual(d2, d3); Assert.AreEqual("one", d1(one)); Assert.AreEqual("two", d1(two)); Assert.AreEqual("three", d1(three)); }