Ejemplo n.º 1
0
        public void FastReflectionMethods()
        {
            var fastReflection = new FastReflection();
            var testValue      = new MockValue();

            Assert.IsNull(fastReflection.InvokeMethod(testValue, nameof(MockValue.VoidMethod)));
            fastReflection.InvokeMethod(testValue, nameof(MockValue.VoidMethod)); // Must call from the cache

            Assert.AreEqual(246, fastReflection.InvokeMethod(testValue, nameof(MockValue.ReturnMethod), 123));



            try
            {
                fastReflection.InvokeMethod(testValue, nameof(MockValue.ReturnMethod), "Bad argument");
                Assert.Fail();
            }
            catch (TypeLoadException)
            {
            }
            catch
            {
                Assert.Fail();
            }



            try
            {
                fastReflection.InvokeMethod(testValue, nameof(MockValue.ReturnMethod), "Bad argument", "Second bad argument");
                Assert.Fail();
            }
            catch (TypeLoadException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }