private static void DataTableCodeGenerator(DataTableProcessor dataTableProcessor, StringBuilder codeContent, object userData) { string dataTableName = (string)userData; codeContent.Replace("__DATA_TABLE_CREATE_TIME__", DateTime.UtcNow.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss.fff")); codeContent.Replace("__DATA_TABLE_NAME_SPACE__", "Gamemain"); codeContent.Replace("__DATA_TABLE_CLASS_NAME__", "DR" + dataTableName); codeContent.Replace("__DATA_TABLE_COMMENT__", dataTableProcessor.GetValue(0, 1) + "。"); codeContent.Replace("__DATA_TABLE_ID_COMMENT__", "获取" + dataTableProcessor.GetComment(dataTableProcessor.IdColumn) + "。"); codeContent.Replace("__DATA_TABLE_PROPERTIES__", GenerateDataTableProperties(dataTableProcessor)); codeContent.Replace("__DATA_TABLE_PARSER__", GenerateDataTableParser(dataTableProcessor)); codeContent.Replace("__DATA_TABLE_PROPERTY_ARRAY__", GenerateDataTablePropertyArray(dataTableProcessor)); }
private static string GenerateDataTableProperties(DataTableProcessor dataTableProcessor) { StringBuilder stringBuilder = new StringBuilder(); bool firstProperty = true; for (int i = 0; i < dataTableProcessor.RawColumnCount; i++) { if (dataTableProcessor.IsCommentColumn(i)) { // 注释列 continue; } if (dataTableProcessor.IsIdColumn(i)) { // 编号列 continue; } if (firstProperty) { firstProperty = false; } else { stringBuilder.AppendLine().AppendLine(); } stringBuilder .AppendLine(" /// <summary>") .AppendFormat(" /// 获取{0}。", dataTableProcessor.GetComment(i)).AppendLine() .AppendLine(" /// </summary>") .AppendFormat(" public {0} {1}", dataTableProcessor.GetLanguageKeyword(i), dataTableProcessor.GetName(i)).AppendLine() .AppendLine(" {") .AppendLine(" get;") .AppendLine(" private set;") .Append(" }"); } return(stringBuilder.ToString()); }