Пример #1
0
        public void TestMethod1()
        {
            var typeName   = Guid.NewGuid().ToString("N");
            var methodName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var constructor = type.Public.Constructor();
                        {
                            constructor.IL.EmitWriteLine("This is Constructor");
                            constructor.Return();
                        }

                        var method = type.Public.Static.Method(methodName);
                        {
                            throw new NotImplementedException("AccessorLambda 가 Type, Method 간 공유되는 문제 해결해야 함");
                            //method.New(type);
                            //method.Return();
                        }
                    }

                    //var releaseType = type.ReleaseType();
                }
            }

            //assembly.AssemblyLambda.Save();
        }
Пример #2
0
        public void Call_StaticMethod_Test()
        {
            var typeName    = Guid.NewGuid().ToString("N");
            var methodName1 = Guid.NewGuid().ToString("N");
            var methodName2 = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Class(typeName);
                    {
                        var method1 = type.Public.Static.Method(methodName1);
                        {
                            method1.IL.EmitWriteLine("This is Dynamic Method (Method1)");
                            method1.Return();
                        }

                        var method2 = type.Public.Static.Method(methodName2);
                        {
                            method2.Emit.EmitWriteLine("Thisis Dynamic Method (Method2)");

                            method2.Call((Operand)method1);
                            method2.Return();
                        }
                    }


                    var releaseType = type.ReleaseType();

                    releaseType.GetMethod(methodName1).Invoke(null, null);
                    releaseType.GetMethod(methodName2).Invoke(null, null);
                }
            }
        }
Пример #3
0
        public void AssemblyLambda_Assembly_Method_Test()
        {
            var assembly = new AssemblyLambda();
            var module = assembly.Assembly();

            assembly.Save();
        }
Пример #4
0
        public void AssemblyLambda_Assembly_Method_Test()
        {
            var assembly = new AssemblyLambda();
            var module   = assembly.Assembly();

            assembly.Save();
        }
Пример #5
0
        public void TypeLambda_Define_Type_Of_Non_Default_Constructor()
        {
            var typeName  = Guid.NewGuid().ToString("N");
            var fieldName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();

            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var field1 = type.Public.Field(typeof(string), fieldName);
                        var con1   = type.Public.Constructor(new ParameterCriteriaMetadataInfo[] { new ParameterCriteriaMetadataInfo(typeof(string), "name") }.AsEnumerable());
                    }

                    var releaseType = type.ReleaseType();

                    var constructor = releaseType.GetConstructors();
                    Assert.IsTrue(constructor.Length == 1, "기본 생성자 없이 1개의 파라메터를 받는 생성자만 존재해야 하는데, 존재하지 않습니다");
                    Assert.IsTrue(constructor[0].GetParameters()[0].Name == "name", "생성자의 파라메터 이름이 'name' 인데 파라미터명이 존재하지 않습니다");
                }
            }

            assembly.AssemblyLambda.Save();
        }
Пример #6
0
        public void TestMethod1()
        {
            var typeName   = Guid.NewGuid().ToString("N");
            var methodName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var constructor = type.Public.Constructor();
                        {
                            constructor.IL.EmitWriteLine("This is Constructor");
                            constructor.Return();
                        }

                        var method = type.Public.Static.Method(methodName);
                        {
                            throw new NotImplementedException("AccessorLambda 가 Type, Method 간 공유되는 문제 해결해야 함");
                            //method.New(type);
                            //method.Return();
                        }
                    }

                    //var releaseType = type.ReleaseType();
                }
            }

            //assembly.AssemblyLambda.Save();
        }
Пример #7
0
        public void Call_StaticMethod_Test()
        {
            var typeName    = Guid.NewGuid().ToString("N");
            var methodName1 = Guid.NewGuid().ToString("N");
            var methodName2 = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Class(typeName);
                    {
                        var method1 = type.Public.Static.Method(methodName1);
                        {
                            method1.IL.EmitWriteLine("This is Dynamic Method (Method1)");
                            method1.Return();
                        }

                        var method2 = type.Public.Static.Method(methodName2);
                        {
                            method2.Emit.EmitWriteLine("Thisis Dynamic Method (Method2)");

                            method2.Call((Operand)method1);
                            method2.Return();
                        }
                    }

                    var releaseType = type.ReleaseType();

                    releaseType.GetMethod(methodName1).Invoke(null, null);
                    releaseType.GetMethod(methodName2).Invoke(null, null);
                }
            }
        }
Пример #8
0
        public void TypeLambda_Define_Method()
        {
            var typeName   = Guid.NewGuid().ToString("N");
            var methodName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();

            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var constructor1 = type.Public.Constructor();
                        {
                            constructor1.Emit.EmitWriteLine("This is constructor");
                            constructor1.Return();
                        }

                        var constructor2 = type.Private.Static.Constructor();
                        {
                            constructor2.Emit.EmitWriteLine("This is (private static) constructor");
                            constructor2.Return();
                        }

                        var method = type.Public.Static.Method(methodName);
                        {
                            method.Emit.EmitWriteLine("This is emitted writeline");
                            method.Return();
                        };
                    };

                    var releaseType = type.ReleaseType();

                    var obj = System.Activator.CreateInstance(releaseType);

                    TestContext.WriteLine("Release type is {0}", releaseType.AssemblyQualifiedName);

                    var releaseMethod = releaseType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                    TestContext.WriteLine("Release method is {0}", releaseMethod.Name);

                    releaseType.GetMethod(methodName).Invoke(null, null);

                    Assert.IsTrue(releaseType.IsClass);
                    Assert.IsTrue(releaseMethod != null);
                }
            };
        }
Пример #9
0
        public void TypeLambda_Define_Struct()
        {
            var typeName = Guid.NewGuid().ToString("N");

            var module = new AssemblyLambda().Assembly().Module();

            {
                var type = module.Public.Struct(typeName);
                {
                };

                var releaseType = type.ReleaseType();

                TestContext.WriteLine(releaseType.AssemblyQualifiedName);

                Assert.IsTrue(typeName == releaseType.Name);
            };
        }
Пример #10
0
        public void TypeLambda_Define_Interface()
        {
            var typeName = Guid.NewGuid().ToString("N");

            var module = new AssemblyLambda().Assembly().Module();
            {
                var type = module.Public.Interface(typeName);
                {
                };

                var releaseType = type.ReleaseType();

                TestContext.WriteLine(releaseType.AssemblyQualifiedName);

                Assert.IsTrue(releaseType.IsInterface);
                Assert.IsTrue(typeName == releaseType.Name);
            };
        }
Пример #11
0
        public void TypeLambda_Define_Enum()
        {
            var typeName = Guid.NewGuid().ToString("N");

            var module = new AssemblyLambda().Assembly().Module();
            {
                var type = module.Public.Enum(typeName);
                {
                    type.DefineLiteral("A", 0);
                    type.DefineLiteral("B", 1);
                };

                var releaseType = type.ReleaseType();

                TestContext.WriteLine(releaseType.AssemblyQualifiedName);

                Assert.IsTrue(releaseType.IsEnum);
                Assert.IsTrue(releaseType.GetFields().Count() == 3); // value__ SpecialName 까지 포함해서 3개여야 함
                Assert.IsTrue(typeName == releaseType.Name);
            };
        }
Пример #12
0
        public void Invoke_Test()
        {
            var assembly = new AssemblyLambda();

            {
                var module = assembly.Assembly("A").Module("A");
                {
                    var type = module.Class(Guid.NewGuid().ToString("N"));

                    var typeAccessor   = new TypeAccessor(type);
                    var methodAccessor = new MethodAccessor(type);
                    var fieldAccessor  = new FieldAccessor(type);

                    var invocation = new AccessorInvocation(type, typeAccessor, methodAccessor, fieldAccessor);

                    var t = invocation.Public;
                    t = invocation.Abstract;
                    t = invocation.Abstract;

                    TestContext.WriteLine("TypeAttribute is {0}", typeAccessor.TypeAttributes.ToString());
                    TestContext.WriteLine("MethodAttribute is {0}", methodAccessor.MethodAttribute.ToString());
                    TestContext.WriteLine("FieldAttribute is {0}", fieldAccessor.FieldAttribute.ToString());


                    // Assert Type
                    Assert.IsTrue((typeAccessor.TypeAttributes & TypeAttributes.Class) == TypeAttributes.Class);
                    Assert.IsTrue((typeAccessor.TypeAttributes & TypeAttributes.Abstract) == TypeAttributes.Abstract);
                    Assert.IsFalse((typeAccessor.TypeAttributes & TypeAttributes.Interface) == TypeAttributes.Interface);

                    // Assert Method
                    Assert.IsTrue((methodAccessor.MethodAttribute & MethodAttributes.Public) == MethodAttributes.Public);
                    Assert.IsTrue((methodAccessor.MethodAttribute & MethodAttributes.Abstract) == MethodAttributes.Abstract);
                    Assert.IsFalse((methodAccessor.MethodAttribute & MethodAttributes.Virtual) == MethodAttributes.Virtual);

                    // Assert Field
                    Assert.IsTrue((fieldAccessor.FieldAttribute & FieldAttributes.Public) == FieldAttributes.Public);
                    Assert.IsFalse((fieldAccessor.FieldAttribute & FieldAttributes.Static) == FieldAttributes.Static);
                };
            };
        }
Пример #13
0
        public void TypeLambda_Creation_Entity()
        {
            var typeName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var constructor = type.Constructor();
                        {
                            //constructor.Emit.Emit()
                        }

                        var property1 = type.Property(typeof(string), "Property1");
                        {
                        }
                    }
                }
            }
        }
Пример #14
0
        public void TypeLambda_Define_Enum()
        {
            var typeName = Guid.NewGuid().ToString("N");

            var module = new AssemblyLambda().Assembly().Module();

            {
                var type = module.Public.Enum(typeName);
                {
                    type.DefineLiteral("A", 0);
                    type.DefineLiteral("B", 1);
                };

                var releaseType = type.ReleaseType();

                TestContext.WriteLine(releaseType.AssemblyQualifiedName);

                Assert.IsTrue(releaseType.IsEnum);
                Assert.IsTrue(releaseType.GetFields().Count() == 3);                 // value__ SpecialName 까지 포함해서 3개여야 함
                Assert.IsTrue(typeName == releaseType.Name);
            };
        }
Пример #15
0
        public void TypeLambda_Creation_Entity()
        {
            var typeName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var constructor = type.Constructor();
                        {
                            //constructor.Emit.Emit()
                        }

                        var property1 = type.Property(typeof(string), "Property1");
                        {
                        }
                    }
                }
            }
        }
Пример #16
0
        public void Invoke_Test()
        {
            var assembly = new AssemblyLambda();
            {
                var module = assembly.Assembly("A").Module("A");
                {
                    var type = module.Class(Guid.NewGuid().ToString("N"));

                    var typeAccessor = new TypeAccessor(type);
                    var methodAccessor = new MethodAccessor(type);
                    var fieldAccessor = new FieldAccessor(type);

                    var invocation = new AccessorInvocation(type, typeAccessor, methodAccessor, fieldAccessor);

                    var t = invocation.Public;
                    t = invocation.Abstract;
                    t = invocation.Abstract;

                    TestContext.WriteLine("TypeAttribute is {0}", typeAccessor.TypeAttributes.ToString());
                    TestContext.WriteLine("MethodAttribute is {0}", methodAccessor.MethodAttribute.ToString());
                    TestContext.WriteLine("FieldAttribute is {0}", fieldAccessor.FieldAttribute.ToString());

                    // Assert Type
                    Assert.IsTrue((typeAccessor.TypeAttributes & TypeAttributes.Class) == TypeAttributes.Class);
                    Assert.IsTrue((typeAccessor.TypeAttributes & TypeAttributes.Abstract) == TypeAttributes.Abstract);
                    Assert.IsFalse((typeAccessor.TypeAttributes & TypeAttributes.Interface) == TypeAttributes.Interface);

                    // Assert Method
                    Assert.IsTrue((methodAccessor.MethodAttribute & MethodAttributes.Public) == MethodAttributes.Public);
                    Assert.IsTrue((methodAccessor.MethodAttribute & MethodAttributes.Abstract) == MethodAttributes.Abstract);
                    Assert.IsFalse((methodAccessor.MethodAttribute & MethodAttributes.Virtual) == MethodAttributes.Virtual);

                    // Assert Field
                    Assert.IsTrue((fieldAccessor.FieldAttribute & FieldAttributes.Public) == FieldAttributes.Public);
                    Assert.IsFalse((fieldAccessor.FieldAttribute & FieldAttributes.Static) == FieldAttributes.Static);
                };
            };
        }
Пример #17
0
        public void Define_Local_Test()
        {
            var typeName    = Guid.NewGuid().ToString("N");
            var methodName1 = Guid.NewGuid().ToString("N");
            var localName1  = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Class(typeName);
                    {
                        var method1 = type.Public.Static.Method(methodName1);
                        {
                            var local1 = method1.Local(typeof(string), localName1);
                            method1.Return();
                        }
                    }

                    var releaseType = type.ReleaseType();
                }
            }
        }
Пример #18
0
        public void Define_Local_Test()
        {
            var typeName    = Guid.NewGuid().ToString("N");
            var methodName1 = Guid.NewGuid().ToString("N");
            var localName1  = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Class(typeName);
                    {
                        var method1 = type.Public.Static.Method(methodName1);
                        {
                            var local1 = method1.Local(typeof(string), localName1);
                            method1.Return();
                        }
                    }

                    var releaseType = type.ReleaseType();
                }
            }
        }
Пример #19
0
        public void ModuleLambda_Delegate_Test()
        {
            var typeName     = Guid.NewGuid().ToString("N");
            var delegateName = Guid.NewGuid().ToString("N");
            var methodName	= Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var @delegate = module.Delegate(typeof(void), delegateName, typeof(string));

                    var type = module.Class(typeName);
                    {
                        var method = type.Public.Static.Method(methodName);
                        {
                            method.Return();
                        }
                    }
                }

                module.ReleaseType();
            }
        }
Пример #20
0
        public void ModuleLambda_Delegate_Test()
        {
            var typeName     = Guid.NewGuid().ToString("N");
            var delegateName = Guid.NewGuid().ToString("N");
            var methodName   = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var @delegate = module.Delegate(typeof(void), delegateName, typeof(string));

                    var type = module.Class(typeName);
                    {
                        var method = type.Public.Static.Method(methodName);
                        {
                            method.Return();
                        }
                    }
                }

                module.ReleaseType();
            }
        }
Пример #21
0
        public void TypeLambda_Define_Method()
        {
            var typeName = Guid.NewGuid().ToString("N");
            var methodName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var constructor1 = type.Public.Constructor();
                        {
                            constructor1.Emit.EmitWriteLine("This is constructor");
                            constructor1.Return();
                        }

                        var constructor2 = type.Private.Static.Constructor();
                        {
                            constructor2.Emit.EmitWriteLine("This is (private static) constructor");
                            constructor2.Return();
                        }

                        var method = type.Public.Static.Method(methodName);
                        {
                            method.Emit.EmitWriteLine("This is emitted writeline");
                            method.Return();
                        };
                    };

                    var releaseType = type.ReleaseType();

                    var obj = System.Activator.CreateInstance(releaseType);

                    TestContext.WriteLine("Release type is {0}", releaseType.AssemblyQualifiedName);

                    var releaseMethod = releaseType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                    TestContext.WriteLine("Release method is {0}", releaseMethod.Name);

                    releaseType.GetMethod(methodName).Invoke(null, null);

                    Assert.IsTrue(releaseType.IsClass);
                    Assert.IsTrue(releaseMethod != null);
                }
            };
        }
Пример #22
0
 public void TypeLambda_Constructor_Test()
 {
     var type = new AssemblyLambda().Assembly().Module().Public.Class("DynamicType");
 }
Пример #23
0
 public void AssemblyLambda_Constructor_Test()
 {
     IAssemblyLambda assembly = new AssemblyLambda();
 }
Пример #24
0
 public void AssemblyLambda_Constructor_Test()
 {
     IAssemblyLambda assembly = new AssemblyLambda();
 }
Пример #25
0
 public void TypeLambda_Constructor_Test()
 {
     var type = new AssemblyLambda().Assembly().Module().Public.Class("DynamicType");
 }
Пример #26
0
 public void ModuleLambda_Constructor_Test()
 {
     var assembly = new AssemblyLambda();
     var module = assembly.Assembly();
 }
Пример #27
0
        public void TypeLambda_Define_Type_Of_Non_Default_Constructor()
        {
            var typeName  = Guid.NewGuid().ToString("N");
            var fieldName = Guid.NewGuid().ToString("N");

            var assembly = new AssemblyLambda().Assembly();
            {
                var module = assembly.Module();
                {
                    var type = module.Public.Class(typeName);
                    {
                        var field1 = type.Public.Field(typeof(string), fieldName);
                        var con1 = type.Public.Constructor( new ParameterCriteriaMetadataInfo[] { new ParameterCriteriaMetadataInfo(typeof(string), "name") }.AsEnumerable());
                    }

                    var releaseType = type.ReleaseType();

                    var constructor = releaseType.GetConstructors();
                    Assert.IsTrue(constructor.Length == 1, "기본 생성자 없이 1개의 파라메터를 받는 생성자만 존재해야 하는데, 존재하지 않습니다");
                    Assert.IsTrue(constructor[0].GetParameters()[0].Name == "name", "생성자의 파라메터 이름이 'name' 인데 파라미터명이 존재하지 않습니다");

                }
            }

            assembly.AssemblyLambda.Save();
        }
Пример #28
0
 public void ModuleLambda_Constructor_Test()
 {
     var assembly = new AssemblyLambda();
     var module   = assembly.Assembly();
 }