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

NonVirtualInstanceInvoker() private method

private NonVirtualInstanceInvoker ( ) : void
return void
        public void NonVirtualInstanceInvoker()
        {
            Type tA = typeof( A );
            Type tB = typeof( B );
            {
                // Null or MissingMethodException.
                Func<A, int, int> fUnk1 = DelegateHelper.GetNonVirtualInvoker<Func<A, int, int>>( tA, "SimpleMethod" );
                Assert.That( fUnk1, Is.Null );

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

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

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

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

                Assert.That( fA( b, 30 ), Is.EqualTo( "30" ) );
                Assert.That( _lastCalledName, Is.EqualTo( "A.SimpleMethod" ), "It is the base A method that is called, even if b overrides it." );
                Assert.That( _lastCalledParam, Is.EqualTo( 30 ) );
            }
        }
    }