private EnumDeclare GetEnumDeclareFromSingleSheet(ISheet sheet)
        {
            EnumDeclare       ret  = new EnumDeclare();
            List <EnumMember> args = new List <EnumMember>();

            for (int rownum = 1; rownum <= sheet.LastRowNum; ++rownum)
            {
                IRow   row        = sheet.GetRow(rownum);
                string part_value = row.GetCell((int)E_SINGLE_ENUM_COLUMN.PART).StringOrNull();
                if (string.IsNullOrEmpty(part_value))
                {
                    continue;
                }

                E_PART part      = (E_PART)Enum.Parse(typeof(E_PART), part_value);
                string attribute = row.GetCell((int)E_SINGLE_ENUM_COLUMN.ATTRIBUTE).StringOrNull();
                string name      = row.GetCell((int)E_SINGLE_ENUM_COLUMN.NAME).StringOrNull();
                string value     = row.GetCell((int)E_SINGLE_ENUM_COLUMN.VALUE).StringOrNull();
                string desc      = row.GetCell((int)E_SINGLE_ENUM_COLUMN.DESC).StringOrNull();

                string[] attributes = null;
                if (!string.IsNullOrEmpty(attribute))
                {
                    attributes = attribute.Split(';').ToArray();
                }

                args.Add(new EnumMember {
                    name = name, value = value, desc = desc, attributes = attributes
                });
            }

            ret.name = sheet.SheetName.Remove(0, ENUM_SHEET_PREFIX.Length);
            ret.args = args.ToArray();
            return(ret);
        }
        private EnumDeclare[] GetEnumDeclares(ISheet sheet)
        {
            List <EnumDeclare> ret = new List <EnumDeclare>();

            for (int rownum = 1; rownum <= sheet.LastRowNum; ++rownum)
            {
                EnumDeclare item = this.GetEnumDeclare(sheet, rownum);
                if (item != null)
                {
                    ret.Add(item);
                }
            }

            return(ret.ToArray());
        }
        private EnumDeclare GetEnumDeclare(ISheet sheet, int rownum)
        {
            EnumDeclare ret      = new EnumDeclare();
            IRow        row      = sheet.GetRow(rownum);
            ICell       partCell = row.GetCell((int)E_ENUM_ROW.PART);

            if (partCell == null)
            {
                return(null);
            }

            ICell attributeCell = row.GetCell((int)E_ENUM_ROW.ATTRIBUTE);
            ICell nameCell      = row.GetCell((int)E_ENUM_ROW.NAME);

            if (string.IsNullOrEmpty(nameCell.StringCellValue))
            {
                return(null);
            }

            E_PART part = (E_PART)Enum.Parse(typeof(E_PART), partCell.StringCellValue);

            string attribute = null;

            if (attributeCell != null)
            {
                attribute = attributeCell.StringCellValue;
            }

            List <string> args = new List <string>();

            for (int cellnum = (int)E_ENUM_ROW.NAME + 1; cellnum < this.GetColumnMax(sheet); ++cellnum)
            {
                ICell cell = row.GetCell(cellnum);
                if (cell == null)
                {
                    break;
                }

                if (string.IsNullOrEmpty(cell.StringCellValue))
                {
                    break;
                }

                args.Add(cell.StringCellValue);
            }

            return(EnumDeclare.GenEnumDeclare(part, attribute, nameCell.StringCellValue, args.ToArray()));
        }
        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);
                }
            }
        }