private ConstDeclare GetConstDeclareFromSingleSheet(ISheet sheet) { ConstDeclare ret = new ConstDeclare(); List <ConstMember> args = new List <ConstMember>(); for (int rownum = 1; rownum <= sheet.LastRowNum; ++rownum) { IRow row = sheet.GetRow(rownum); if (row == null) { continue; } string partvalue = row.GetCell((int)E_SINGLE_CONST_COLUMN.PART).StringOrNull(); if (string.IsNullOrEmpty(partvalue)) { continue; } E_PART part = (E_PART)Enum.Parse(typeof(E_PART), partvalue); string typevalue = row.GetCell((int)E_SINGLE_CONST_COLUMN.TYPE).StringOrNull(); string attribute = row.GetCell((int)E_SINGLE_CONST_COLUMN.ATTRIBUTE).StringOrNull(); string name = row.GetCell((int)E_SINGLE_CONST_COLUMN.NAME).StringCellValue; string value = row.GetCell((int)E_SINGLE_CONST_COLUMN.VALUE).StringOrNull(); string desc = row.GetCell((int)E_SINGLE_CONST_COLUMN.DESC).StringOrNull(); string[] attributes = null; if (!string.IsNullOrEmpty(attribute)) { attributes = attribute.Split(';').ToArray(); } args.Add(new ConstMember { part = part, type = typevalue, name = name, value = value, desc = desc, attributes = attributes }); } ret.name = sheet.SheetName.Remove(0, COST_SHEET_PREFIX.Length); ret.const_members = args.ToArray(); return(ret); }
public void Render(string templateDir, string outputDir) { string tplConst = File.ReadAllText(Path.Combine(templateDir, "const.liquid")); string tplEnum = File.ReadAllText(Path.Combine(templateDir, "enum.liquid")); string tplClass = File.ReadAllText(Path.Combine(templateDir, "class.liquid")); Template genConst = this.GetGenerator(tplConst); Template genEnum = this.GetGenerator(tplEnum); Template genClass = this.GetGenerator(tplClass); Dictionary <string, Template> classDic = this.GetClassRenderDic(templateDir); List <ClassDeclare> lst = new List <ClassDeclare>(); for (int sheetIndex = 0; sheetIndex < this._reader.NumberOfSheets; ++sheetIndex) { ISheet sheet = this._reader.GetSheetAt(sheetIndex); string sheetname = sheet.SheetName; if (sheetname.StartsWith(COST_SHEET_PREFIX)) { ConstDeclare constDeclare = this.GetConstDeclareFromSingleSheet(sheet); string path = Path.Combine(outputDir, $"const_{constDeclare.name}.cs"); this.WriteToFile(path, genConst.Render(Hash.FromAnonymousObject(new { c = constDeclare }))); } else if (sheetname == SINGLE_ENUM_SHEETNAME) { EnumDeclare[] enumDeclares = this.GetEnumDeclares(sheet); string path = Path.Combine(outputDir, "enum.autogen.cs"); this.WriteToFile(path, genEnum.Render(Hash.FromAnonymousObject(new { list = enumDeclares }))); } else if (sheetname.StartsWith(ENUM_SHEET_PREFIX)) { EnumDeclare enumDeclare = this.GetEnumDeclareFromSingleSheet(sheet); string path = Path.Combine(outputDir, $"enum_{enumDeclare.name}.cs"); this.WriteToFile(path, genEnum.Render(Hash.FromAnonymousObject(new { list = new[] { enumDeclare } }))); } if (sheetname.StartsWith(IGNORE_PREFIX)) { continue; } if (classDic.ContainsKey(sheet.SheetName)) { string path = Path.Combine(outputDir, $"class_{sheet.SheetName}.autogen.cs"); this.WriteToFile(path, classDic[sheet.SheetName] .Render(Hash.FromAnonymousObject(new { c = this.GetClaassDeclare(sheet) }))); } else { lst.Add(this.GetClaassDeclare(sheet)); } } string pathc = Path.Combine(outputDir, "class.autogen.cs"); this.WriteToFile(pathc, genClass.Render(Hash.FromAnonymousObject(new { date = DateTime.Now, list = lst }))); foreach (FileInfo file in new DirectoryInfo(templateDir).GetFiles()) { if (file.Name.EndsWith(".cs")) { string temppath = Path.Combine(outputDir, file.Name); file.CopyTo(temppath, true); } } }