예제 #1
0
        public void Test_生成实体代理类程序集()
        {
            Type[] entityTypes = new Type[] { typeof(Product), typeof(Customer) };
            string dllFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test.EntityProxy.dll");

            if (File.Exists(dllFilePath))
            {
                File.Delete(dllFilePath);
            }

            var result = ProxyBuilder.Compile(entityTypes, dllFilePath);

            Assert.IsTrue(File.Exists(dllFilePath));

            // 加载程序集并确认结果
            Assembly asm = Assembly.LoadFrom(dllFilePath);

            Type[] types = asm.GetExportedTypes();

            var t1 = (from x in types
                      where x.Name.StartsWith("Customer_") && x.Name.EndsWith("_Loader")
                      select x).First();

            var t2 = (from x in types
                      where x.Name.StartsWith("Customer_") && x.Name.EndsWith("_Proxy")
                      select x).First();

            var t3 = (from x in types
                      where x.Name.StartsWith("Product_") && x.Name.EndsWith("_Loader")
                      select x).First();

            var t4 = (from x in types
                      where x.Name.StartsWith("Product_") && x.Name.EndsWith("_Proxy")
                      select x).First();
        }
예제 #2
0
        private static void Execute(string dllFile, Assembly asm = null)
        {
            string currentPath = Path.GetDirectoryName(dllFile);

            string newName = Path.GetFileNameWithoutExtension(dllFile) + ".EntityProxy.dll";
            string outFile = Path.Combine(currentPath, newName);

            if (File.Exists(outFile))
            {
                File.Delete(outFile);
            }

            if (asm == null)
            {
                asm = Assembly.LoadFrom(dllFile);
            }

            Type[] entityTypes = ProxyBuilder.GetAssemblyEntityTypes(asm);
            if (entityTypes == null || entityTypes.Length == 0)
            {
                return;
            }

            ProxyBuilder.Compile(entityTypes, outFile);

            Console.WriteLine("成功生成实体代理程序集:" + outFile);
        }
예제 #3
0
        private static void Execute(string entityDllFile)
        {
            string currentPath = Path.GetDirectoryName(entityDllFile);

            if (string.IsNullOrEmpty(currentPath))
            {
                currentPath = AppDomain.CurrentDomain.BaseDirectory;
            }


            string newName = Path.GetFileNameWithoutExtension(entityDllFile) + ".EntityProxy.dll";
            string outFile = Path.Combine(currentPath, newName);

            if (File.Exists(outFile))
            {
                File.Delete(outFile);
            }

            // 设置当前路径
            Environment.CurrentDirectory = currentPath;

            Assembly asm = Assembly.LoadFile(entityDllFile);

            Type[] entityTypes = ProxyBuilder.GetAssemblyEntityTypes(asm);

            ProxyBuilder.Compile(entityTypes, outFile);
        }