public void GetFastInvoker_DerivedClassPrivateMethod_Get() { var methodInfo = typeof(ClassWithReferenceType <string>).GetMethod("get_PrivateProperty", BindingFlags.Instance | BindingFlags.NonPublic); var adapter = MethodInfoAdapter.Create(methodInfo); var instance = new DerivedClassWithReferenceType <string>(); PrivateInvoke.SetNonPublicProperty(instance, "PrivateProperty", "Test"); var result = adapter.GetFastInvoker <Func <ClassWithReferenceType <string>, string> >(); Assert.That(result.GetType(), Is.EqualTo(typeof(Func <ClassWithReferenceType <string>, string>))); Assert.That(result(instance), Is.EqualTo("Test")); }
public void GetFastInvoker_DerivedClassPrivateMethod_Set() { var methodInfo = typeof(ClassWithReferenceType <string>).GetMethod("set_PrivateProperty", BindingFlags.Instance | BindingFlags.NonPublic); var adapter = MethodInfoAdapter.Create(methodInfo); var instance = new DerivedClassWithReferenceType <string>(); instance.ImplicitInterfaceScalar = "Test"; var result = adapter.GetFastInvoker <Action <ClassWithReferenceType <string>, string> >(); result(instance, "Test"); Assert.That(PrivateInvoke.GetNonPublicProperty(instance, "PrivateProperty"), Is.EqualTo("Test")); Assert.That(result.GetType(), Is.EqualTo(typeof(Action <ClassWithReferenceType <string>, string>))); }