CK.Reflection.Tests.ObjectAndType.InstanceInvoker C# (CSharp) Method

InstanceInvoker() private method

private InstanceInvoker ( ) : void
return void
        public void InstanceInvoker()
        {
            Type tA = typeof( A );
            Type tB = typeof( B );

            {
                // Null or MissingMethodException.
                Func<A, int, int> fUnk1 = DelegateHelper.GetInstanceInvoker<Func<A, int, int>>( tA, "SimpleMethod" );
                Assert.That( fUnk1, Is.Null );

                Func<A, int, string> fUnk2 = DelegateHelper.GetInstanceInvoker<Func<A, int, string>>( tA, "SimpleMethoddUnk" );
                Assert.That( fUnk2, Is.Null );

                Assert.Throws<MissingMethodException>( () => DelegateHelper.GetInstanceInvoker<Func<A, int, int>>( tA, "SimpleMethod", true ) );
                Assert.Throws<MissingMethodException>( () => DelegateHelper.GetInstanceInvoker<Func<A, int, string>>( tA, "SimpleMethodUnk", true ) );

                Assert.That( DelegateHelper.GetInstanceInvoker<Func<A, int, int>>( tA, "SimpleMethod", false ), Is.Null );
                Assert.That( DelegateHelper.GetInstanceInvoker<Func<A, int, string>>( tA, "SimpleMethodUnk", false ), Is.Null );
            }

            A a = new A();
            B b = new B();
            {
                Func<A,int, string> fA = DelegateHelper.GetInstanceInvoker<Func<A, int, string>>( tA, "SimpleMethod" );
                Assert.That( fA( a, 2 ), Is.EqualTo( "2" ) );
                Assert.That( _lastCalledName, Is.EqualTo( "A.SimpleMethod" ) );
                Assert.That( _lastCalledParam, Is.EqualTo( 2 ) );

                Assert.That( fA( b, 3 ), Is.EqualTo( "3" ) );
                Assert.That( _lastCalledName, Is.EqualTo( "B.SimpleMethod" ), "Calling the virtual method: B method." );
                Assert.That( _lastCalledParam, Is.EqualTo( 3 ) );
            }
        }