Ejemplo n.º 1
0
        public void TestMethod6()
        {
            DynamicMethodSkeleton    dynamicMethodSkeleton = new DynamicMethodSkeleton();
            Action <IMethodSkeleton> firstEmitter          =
                skeleton =>
            {
                ConstructorInfo barConstructorInfo = typeof(Bar).GetConstructors().First();
                skeleton.GetILGenerator().Emit(OpCodes.Newobj, barConstructorInfo);
            };
            Action <IMethodSkeleton> secondEmitter =
                skeleton =>
            {
                ConstructorInfo fooConstructorInfo = typeof(Foo).GetConstructors().First();
                skeleton.GetILGenerator().Emit(OpCodes.Newobj, fooConstructorInfo);
            };

            Action <IMethodSkeleton> doit = skeleton =>
            {
                firstEmitter(dynamicMethodSkeleton);
                secondEmitter(dynamicMethodSkeleton);
            };

            doit(dynamicMethodSkeleton);

            var del      = dynamicMethodSkeleton.CreateDelegate();
            var instance = del(new object[] { });

            Assert.IsNotNull(instance);
        }
Ejemplo n.º 2
0
 public void TestMethod5()
 {
     ConstructorInfo barConstructorInfo = TypeHelper.GetConstructors(typeof(Bar)).First();
     ConstructorInfo fooConstructorInfo = TypeHelper.GetConstructors(typeof(Foo)).First();
     DynamicMethodSkeleton dynamicMethodSkeleton = new DynamicMethodSkeleton();
     var generator = dynamicMethodSkeleton.GetILGenerator();
     generator.Emit(OpCodes.Newobj, barConstructorInfo);
     generator.Emit(OpCodes.Newobj, fooConstructorInfo);
     var del = dynamicMethodSkeleton.CreateDelegate();
     var instance = del(new object[] { });
     Assert.IsNotNull(instance);
 }
Ejemplo n.º 3
0
        public void TestMethod5()
        {
            ConstructorInfo       barConstructorInfo    = typeof(Bar).GetTypeInfo().DeclaredConstructors.First();
            ConstructorInfo       fooConstructorInfo    = typeof(FooWithDependency).GetTypeInfo().DeclaredConstructors.First();
            DynamicMethodSkeleton dynamicMethodSkeleton = new DynamicMethodSkeleton();
            var generator = dynamicMethodSkeleton.GetILGenerator();

            generator.Emit(OpCodes.Newobj, barConstructorInfo);
            generator.Emit(OpCodes.Newobj, fooConstructorInfo);
            var del      = dynamicMethodSkeleton.CreateDelegate();
            var instance = del(new object[] { });

            Assert.IsNotNull(instance);
        }
Ejemplo n.º 4
0
        public void TestMethod5()
        {
            ConstructorInfo       barConstructorInfo    = TypeHelper.GetConstructors(typeof(Bar)).First();
            ConstructorInfo       fooConstructorInfo    = TypeHelper.GetConstructors(typeof(Foo)).First();
            DynamicMethodSkeleton dynamicMethodSkeleton = new DynamicMethodSkeleton();
            var generator = dynamicMethodSkeleton.GetILGenerator();

            generator.Emit(OpCodes.Newobj, barConstructorInfo);
            generator.Emit(OpCodes.Newobj, fooConstructorInfo);
            var del      = dynamicMethodSkeleton.CreateDelegate();
            var instance = del(new object[] { });

            Assert.IsNotNull(instance);
        }
Ejemplo n.º 5
0
        public void TestMethod6()
        {
            DynamicMethodSkeleton dynamicMethodSkeleton = new DynamicMethodSkeleton();
            Action<IMethodSkeleton> firstEmitter =
                skeleton =>
                    {
                        ConstructorInfo barConstructorInfo = typeof(Bar).GetConstructors().First();
                        skeleton.GetILGenerator().Emit(OpCodes.Newobj, barConstructorInfo);
                    };
            Action<IMethodSkeleton> secondEmitter =
                skeleton =>
                    {
                        ConstructorInfo fooConstructorInfo = typeof(Foo).GetConstructors().First();
                        skeleton.GetILGenerator().Emit(OpCodes.Newobj, fooConstructorInfo);
                    };

            Action<IMethodSkeleton> doit = skeleton =>
                {
                    firstEmitter(dynamicMethodSkeleton);
                    secondEmitter(dynamicMethodSkeleton);
                };

            doit(dynamicMethodSkeleton);

            var del = dynamicMethodSkeleton.CreateDelegate();
            var instance = del(new object[] { });
            Assert.IsNotNull(instance);
        }
 public void TestMethod5()
 {
     ConstructorInfo barConstructorInfo = typeof(Bar).GetTypeInfo().DeclaredConstructors.First();
     ConstructorInfo fooConstructorInfo = typeof(FooWithDependency).GetTypeInfo().DeclaredConstructors.First();
     DynamicMethodSkeleton dynamicMethodSkeleton = new DynamicMethodSkeleton();
     var generator = dynamicMethodSkeleton.GetILGenerator();
     generator.Emit(OpCodes.Newobj, barConstructorInfo);
     generator.Emit(OpCodes.Newobj, fooConstructorInfo);
     var del = dynamicMethodSkeleton.CreateDelegate();
     var instance = del(new object[] { });
     Assert.IsNotNull(instance);
 }