private static void DataTableCodeGenerator(DataTableProcessor dataTableProcessor, StringBuilder codeContent, object userData) { string dataTableName = (string)userData; codeContent.Replace("__DATA_TABLE_CREATE_TIME__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); codeContent.Replace("__DATA_TABLE_NAME_SPACE__", "StarForce"); 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(); } string typeName = dataTableProcessor.GetLanguageKeyword(i); if (dataTableProcessor.IsList(i)) { typeName = "List<" + dataTableProcessor.GetLanguageKeyword(i) + ">"; } stringBuilder .AppendLine(" /// <summary>") .AppendFormat(" /// 获取{0}。", dataTableProcessor.GetComment(i)).AppendLine() .AppendLine(" /// </summary>") .AppendFormat(" public {0} {1}", typeName, dataTableProcessor.GetName(i)).AppendLine() .AppendLine(" {") .AppendLine(" get;") .AppendLine(" private set;") .Append(" }"); } return(stringBuilder.ToString()); }
//数据表脚本生成器 private static void CustomDataTableCodeGenerator(DataTableProcessor dataTableProcessor, StringBuilder codeContent, object userData) { string dataTableName = (string)userData; codeContent.Replace("__DATA_TABLE_CREATE_TIME__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); //替换数据表创建时间 codeContent.Replace("__DATA_TABLE_NAME_SPACE__", "Game.Runtime"); //替换数据表所在命名空间,这里去掉命名空间 codeContent.Replace("__DATA_TABLE_CLASS_NAME__", DataTableExtension.DataRowClassPrefixName + dataTableName); //类名 codeContent.Replace("__DATA_TABLE_COMMENT__", dataTableProcessor.GetValue(0, 1)); //脚本注释名 codeContent.Replace("__DATA_TABLE_ID_COMMENT__", "获取" + dataTableProcessor.GetComment(dataTableProcessor.IdColumn)); //id注释 codeContent.Replace("__DATA_TABLE_PROPERTIES__", GenerateDataTableProperties(dataTableProcessor)); codeContent.Replace("__DATA_TABLE_STRING_PARSER__", GenerateDataTableStringParser(dataTableProcessor)); codeContent.Replace("__DATA_TABLE_BYTES_PARSER__", GenerateDataTableBytesParser(dataTableProcessor)); codeContent.Replace("__DATA_TABLE_STREAM_PARSER__", GenerateDataTableStreamParser(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)) .Append("{ get; private set; }"); //.Append(" {") //.Append(" get;") //.Append(" private set;") //.Append(" }"); } return(stringBuilder.ToString()); }