Beispiel #1
0
        /// <summary>
        /// 创建代码
        /// </summary>
        /// <param name="dllFile"></param>
        /// <param name="outFile"></param>
        public static void CreateCode(string dllFile, string outFile)
        {
            StringBuilder codeBuilder = new StringBuilder();

            var           dll             = Assembly.LoadFrom(dllFile);
            StringBuilder proxyregBuilder = new StringBuilder();

            foreach (var type in dll.GetTypes())
            {
                if (type.IsInterface)
                {
                    var i = type.GetInterface("DogSE.Server.Core.LogicModule.ILogicModule");
                    if (i != null)
                    {
                        Console.WriteLine(type.ToString());

                        var crc = new CreateReadCode(type);
                        codeBuilder.Append(crc.CreateCode());
                        proxyregBuilder.Append(crc.CreateRegisterProxyCode());
                    }
                }
            }

            var fileContext = FileCodeBase
                              .Replace("#code#", codeBuilder.ToString())
                              .Replace("#proxyregister#", proxyregBuilder.ToString())
                              .Replace("`", "\"");

            File.WriteAllText(outFile, fileContext, Encoding.UTF8);
        }
        /// <summary>
        /// 创建代码
        /// </summary>
        /// <remarks>
        /// 这里需要输出3组文件
        /// 1.客户端接口
        /// 2.代理类
        /// 3.代理类和接口的绑定
        /// </remarks>
        /// <param name="dllFile"></param>
        /// <param name="outFolder">输出目录</param>
        /// <param name="nameSpace">基础的命名空间</param>
        public static void CreateCode(string dllFile, string outFolder, string nameSpace)
        {
            StringBuilder interfaceCode = new StringBuilder();

            var           dll             = Assembly.LoadFrom(dllFile);
            StringBuilder proxyregBuilder = new StringBuilder();

            foreach (var type in dll.GetTypes())
            {
                if (type.IsInterface)
                {
                    var i = type.GetCustomAttributes(typeof(ClientInterfaceAttribute), true);
                    if (i.Length > 0)
                    {
                        //  将接口代码的代码重新复制过去
                        var code = new CreateInterfaceCode(type).CreateCode();
                        interfaceCode.Append(code);

                        //  生成客户端解包代码并写入对应文件
                        code = new CreateReadCode(type).CreateCode();

                        string typeName = Utils.GetFixInterfaceName(type.Name);

                        var context = FileCodeBase
                                      .Replace("#code#", code)
                                      .Replace("#namespace#", nameSpace)
                                      .Replace("#ClassName#", typeName)
                                      .Replace("`", "\"");

                        string fileName = Path.Combine(outFolder, string.Format(@"Controller\{0}\{0}Controller.Net.cs", typeName));
                        var    fi       = new FileInfo(fileName);
                        if (!fi.Directory.Exists)
                        {
                            fi.Directory.Create();
                        }

                        File.WriteAllText(fileName, context, Encoding.UTF8);
                    }
                }
            }
            var fileContext = InterfaceCodeBase
                              .Replace("#code#", interfaceCode.ToString())
                              .Replace("#namespace#", nameSpace)
                              .Replace("`", "\"");

            var file = Path.Combine(outFolder, @"Controller\Auto\LogicInterface.cs");

            new FileInfo(file).Directory.Create();

            File.WriteAllText(file, fileContext, Encoding.UTF8);
        }
Beispiel #3
0
        /// <summary>
        /// 创建代码
        /// </summary>
        /// <param name="dllFile"></param>
        /// <param name="outFile"></param>
        public static void CreateCode(string dllFile, string outFile)
        {
            StringBuilder codeBuilder = new StringBuilder();

            var dll = Assembly.LoadFrom(dllFile);

            Type clientProxyType = null;

            foreach (var type in dll.GetTypes())
            {
                if (type.Name == "ClientProxy")
                {
                    clientProxyType = type;
                }

                if (type.IsInterface)
                {
                    var i = type.GetCustomAttributes(typeof(ClientInterfaceAttribute), true);
                    if (i.Length > 0)
                    {
                        var code = new CreateProxyCode(type).CreateCode();
                        codeBuilder.Append(code);
                    }
                }
            }

            StringBuilder registerCode = new StringBuilder();

            if (clientProxyType != null)
            {
                foreach (var p in clientProxyType.GetProperties())
                {
                    registerCode.AppendFormat("{0}.{1} = new {2}Proxy1();\r\n", clientProxyType.FullName, p.Name, p.PropertyType.Name);
                }
            }

            var fileContext = FileCodeBase
                              .Replace("#code#", codeBuilder.ToString())
                              .Replace("#proxyregister#", registerCode.ToString());

            //.Replace("#using#", string.Format("using {0};", clientProxyType.FullName));

            File.WriteAllText(outFile, fileContext, Encoding.UTF8);
        }
Beispiel #4
0
        /// <summary>
        /// 创建代码
        /// </summary>
        /// <param name="dllFile"></param>
        /// <param name="outFolder"></param>
        /// <param name="nameSpace"></param>
        public static void CreateCode(string dllFile, string outFolder, string nameSpace)
        {
            StringBuilder codeBuilder = new StringBuilder();

            var dll = Assembly.LoadFrom(dllFile);

            var xmlFile = dllFile.Replace(".dll", ".xml");
            var xmlDoc  = CodeCommentUtils.LoadXmlDocument(xmlFile);

            foreach (var type in dll.GetTypes())
            {
                if (type.IsInterface)
                {
                    var i = type.GetInterface("DogSE.Server.Core.LogicModule.ILogicModule");
                    if (i != null)
                    {
                        Console.WriteLine(type.ToString());

                        var crc  = new CreateProxyCode(type, xmlDoc);
                        var code = crc.CreateCode();

                        string typeName = Utils.GetFixInterfaceName(type.Name);

                        string fileName = Path.Combine(outFolder, string.Format(@"Controller\{0}\{0}Controller.Proxy.cs", typeName));
                        var    fi       = new FileInfo(fileName);
                        if (!fi.Directory.Exists)
                        {
                            fi.Directory.Create();
                        }

                        var fileContext = FileCodeBase
                                          .Replace("#code#", code)
                                          .Replace("#namepace#", nameSpace)
                                          .Replace("#TypeName#", typeName)
                                          .Replace("`", "\"");

                        File.WriteAllText(fileName, fileContext, Encoding.UTF8);
                    }
                }
            }
        }