Exemplo n.º 1
0
        public void InstantiateStructWithConstructor()
        {
            var method = CreateMethod(block =>
            {
                EmitConstructor constructor = typeof(StructWithConstructor).GetConstructors()[0];
                block.Return(constructor.New("foo"));
            });
            var result = (StructWithConstructor)method.Invoke(null, null);

            Assert.AreEqual("foo", result.StringProperty);
        }
Exemplo n.º 2
0
        public void InstantiateClass()
        {
            var method = CreateMethod(block =>
            {
                EmitConstructor constructorInfo = typeof(InstanceClass).GetConstructor(new Type[0]);
                block.Return(constructorInfo.New());
            });
            var result = method.Invoke(null, null);

            Assert.IsTrue(result is InstanceClass);
        }