public static void Gen(GenTypes genTypes, string rootNamespace, string outPath, Assembly asm) { // 提示:生成时, md5 部分内容用 GenUtils.MD5PlaceHolder 占位. 存盘时会被替换为真正 md5 var gt = (int)genTypes; if ((gt & (int)GenTypes.CppClass) > 0) { if (!GenTypeId.Gen(asm, outPath, rootNamespace)) { TipsAndExit("生成停止:" + rootNamespace + "_TypeIdMappings.cs 已生成. 请将其放入 源码文件或目录清单 并再次生成. "); } GenCPP_Class.Gen(asm, outPath, rootNamespace); } if ((gt & (int)GenTypes.CppClassLite) > 0) { GenCPP_Class_Lite.Gen(asm, outPath, rootNamespace); } if ((gt & (int)GenTypes.CppClassFilter) > 0) { if (!GenTypeId.Gen(asm, outPath, rootNamespace)) { TipsAndExit("生成停止:" + rootNamespace + "_TypeIdMappings.cs 已生成. 请将其放入 源码文件或目录清单 并再次生成. "); } GenCPP_Class.Gen(asm, outPath, rootNamespace, new TemplateLibrary.Filter <TemplateLibrary.CppFilter>(asm)); } if ((gt & (int)GenTypes.CppSqlite) > 0) { if (!GenTypeId.Gen(asm, outPath, rootNamespace)) { TipsAndExit("生成停止:" + rootNamespace + "_TypeIdMappings.cs 已生成. 请将其放入 源码文件或目录清单 并再次生成. "); } GenCPP_SQLite.Gen(asm, outPath, rootNamespace); } if ((gt & (int)GenTypes.CSharpClass) > 0) { //if (!GenTypeId.Gen(asm, outPath, rootNamespace)) { // TipsAndExit("生成停止:" + rootNamespace + "_TypeIdMappings.cs 已生成. 请将其放入 源码文件或目录清单 并再次生成. "); //} GenCS_Class.Gen(asm, outPath, rootNamespace); } if ((gt & (int)GenTypes.CSharpMySql) > 0) { if (!GenTypeId.Gen(asm, outPath, rootNamespace)) { TipsAndExit("生成停止:" + rootNamespace + "_TypeIdMappings.cs 已生成. 请将其放入 源码文件或目录清单 并再次生成. "); } GenCS_MySql.Gen(asm, outPath, rootNamespace); } if ((gt & (int)GenTypes.LuaClassFilter) > 0) { if (!GenTypeId.Gen(asm, outPath, rootNamespace)) { TipsAndExit("生成停止:" + rootNamespace + "_TypeIdMappings.cs 已生成. 请将其放入 源码文件或目录清单 并再次生成. "); } GenLUA_Class.Gen(asm, outPath, rootNamespace, new TemplateLibrary.Filter <TemplateLibrary.LuaFilter>(asm)); } // ... }
public static void Main(string[] args) { //var cfg = DeSerialize<Cfg>(File.ReadAllText(args[0])); //// todo //return; if (args.Length < 3) { TipsAndExit(@" *.cs -> codes 生成器使用提示: 缺参数: 根命名空间, 输出目录, 源码文件清单( 完整路径, 可多个 ) 输出目录: 如果缺失,默认为 工作目录. 必须已存在, 不会帮忙创建 源码文件或目录清单: 如果缺失,默认为 工作目录下 *.cs "); } var rootNamespace = args[0]; var outPath = "."; var inPaths = new List <string>(); if (args.Length > 1) { if (!Directory.Exists(args[1])) { TipsAndExit("参数2 错误:目录不存在"); } outPath = args[1]; } var fileNames = new HashSet <string>(); for (int i = 2; i < args.Length; ++i) { if (!File.Exists(args[i])) { TipsAndExit("参数 " + i + 1 + " 错误:文件不存在: " + args[i]); } else { fileNames.Add(args[i]); } } var asm = CreateAssembly(fileNames); if (asm == null) { return; } Console.WriteLine("开始生成"); try { GenCPP_Class_Lite.Gen(asm, outPath, rootNamespace); } catch (Exception ex) { TipsAndExit("生成失败: " + ex.Message + "\r\n" + ex.StackTrace); } TipsAndExit("生成完毕"); //var fn = Path.Combine(Environment.CurrentDirectory, "Program.cs"); //var asm = GetAssembly(new string[] { fn }); //if (asm != null) { // asm.GetType("Program").GetMethod("Test").Invoke(null, null); //} //else Console.ReadLine(); }