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

            RetryFile.Delete(dllFilePath);

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

            Assert.IsTrue(RetryFile.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();
        }
Exemplo n.º 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);

            RetryFile.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);
        }