public void GetFastMethodInvoker_ForStaticGenericMethod()
        {
            var instance = new ClassWithMethods();
            var invoker  = _generator.GetFastMethodInvoker(
                instance.GetType(),
                "Count", new[] { typeof(int) },
                new[] { typeof(IEnumerable <int>), typeof(int) }, BindingFlags.Public | BindingFlags.Static);

            var output = invoker(instance, new object[] { new[] { 3, 1, 2 }, 1 });

            Assert.That(output, Is.EqualTo(4));
        }
        public void GetFastMethodInvoker_ForGenericMethodTwoParameters()
        {
            var instance = new ClassWithMethods();
            var invoker  = _generator.GetFastMethodInvoker(
                instance.GetType(),
                "Count", new[] { typeof(int), typeof(string) },
                new[] { typeof(IEnumerable <int>), typeof(string) }, BindingFlags.Public | BindingFlags.Instance);

            var output = invoker(instance, new object[] { new[] { 3, 1, 2 }, "asdf" });

            Assert.That(output, Is.EqualTo(7));
        }
        public void GetFastMethodInvoker_ForGenericMethodTwoParameters()
        {
            var instance = new ClassWithMethods ();
              var invoker = _generator.GetFastMethodInvoker (
              instance.GetType (),
              "Count", new[] { typeof (int), typeof(string) },
              new[] { typeof (IEnumerable<int>), typeof (string) }, BindingFlags.Public | BindingFlags.Instance);

              var output = invoker (instance, new object[] { new[] { 3, 1, 2 }, "asdf" });

              Assert.That (output, Is.EqualTo (7));
        }
Beispiel #4
0
        public void CallingInternalMethodFromProjectWithoutAccess()
        {
            // Arrange
            var sut = new ClassWithMethods();

            // var greeting = sut.InternalMethod("human");
            // Doesn't compile, because InternalMethod is not
            // accessible here. Instead, we could use reflection:

            BindingFlags bf = BindingFlags.NonPublic | BindingFlags.Instance;
            MethodInfo   mi = sut.GetType().GetMethod("InternalMethod", bf);

            // Act
            var result = (string)mi.Invoke(sut, new object[] { "human" });

            // Assert
            Assert.AreEqual(result, "Howdy human");
        }
        public void GetFastMethodInvoker_ForStaticGenericMethod()
        {
            var instance = new ClassWithMethods();
              var invoker = _generator.GetFastMethodInvoker (
              instance.GetType(),
              "Count", new[] { typeof(int) },
              new[] { typeof (IEnumerable<int>), typeof(int) }, BindingFlags.Public | BindingFlags.Static);

              var output = invoker(instance, new object[] { new[] { 3, 1, 2 }, 1 });

              Assert.That (output, Is.EqualTo (4));
        }