public MethodTests()
        {
            MethodInfo mi = typeof(string).GetMethod("IndexOf", new[] { typeof(string) });

            m_IndexOf1 = Accelerator.CreateFunction2(mi);
            m_IndexOf2 = Accelerator.CreateInvocationDelegate(mi);
        }
Beispiel #2
0
        public void TestCreateConstructor5()
        {
            new ExampleClass1();
            Assert.IsNull(default(ExampleClass1));
            ConstructorInfo    ci     = Accelerator.RetrieveStandardConstructor(typeof(ExampleClass1));
            InvocationDelegate create = Accelerator.CreateInvocationDelegate(ci);

            Assert.IsNotNull(create);
            Assert.IsTrue(create() is ExampleClass1);
        }
Beispiel #3
0
        public void TestInvokeConstructor()
        {
            Type               t      = typeof(ClassWithConstructors);
            ConstructorInfo    ci     = t.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(int), typeof(string) }, null);
            InvocationDelegate create = Accelerator.CreateInvocationDelegate(ci);

            Assert.IsNotNull(create);

            var o = new ClassWithConstructors(123, "ABC");

            Assert.AreEqual(123, o.Value);
            Assert.AreEqual("ABC", o.Text);

            o = (ClassWithConstructors)create(123, "ABC");
            Assert.AreEqual(123, o.Value);
            Assert.AreEqual("ABC", o.Text);

            o = (ClassWithConstructors)create(0, null);
            Assert.AreEqual(0, o.Value);
            Assert.AreEqual(null, o.Text);
        }