Пример #1
0
        /// <summary>
        /// 生成实体内容
        /// </summary>
        /// <param name="content">未转换内容</param>
        /// <param name="generator">代码生成参数</param>
        /// <param name="tableName">表名</param>
        /// <returns>转换后内容</returns>
        public static string GenerateEntity(string content, GenerateParam generator, string tableName, IsqlAdapter sqlAdapter)
        {
            var forRegex = new Regex(@"(?<={{yx-columns}})[\s\S]*(?={{yx-end}})");

            content = content.Replace("{{yx-namespace}}", generator.nameSpace)
                      .Replace("{{yx-modifier}}", generator.modifier)
                      .Replace("{{yx-tableName}}", tableName);
            if (forRegex.IsMatch(content))
            {
                var columns         = sqlAdapter.GetColumnsByTableName(tableName);
                var matchCollection = forRegex.Matches(content);
                foreach (Match match in matchCollection)
                {
                    foreach (var column in columns)
                    {
                        match.Value.Replace("{{yx-columnType}}", TypeConvertorOper.Convert(column.columnType));
                    }
                }
            }
        }
Пример #2
0
 private void generator_btn_Click(object sender, EventArgs e)
 {
     foreach (TreeNode topNode in table_tvw.TopNode.Nodes)
     {
         foreach (TreeNode node in topNode.Nodes)
         {
             if (node.Checked)
             {
                 var content = cSharp_content_rtx.Text.Replace("yx-namespace", cSharp_namespace_txt.Text)
                               .Replace("yx-modifier", cSharp_modifier_txt.Text)
                               .Replace("yx-tableName", node.Text);
                 var columnInfos  = sqlAdapter.GetColumnsByTableName(node.Text);
                 var columnBuider = new StringBuilder();
                 foreach (var column in columnInfos)
                 {
                     // columnBuider.Append("public " + TypeConvert.ConvertToCSharp(column.columnType) + " " + column.columnName + "{get;set;}");
                     columnBuider.Append("\r\n");
                 }
                 content = content.Replace("yx-content", columnBuider.ToString());
             }
         }
     }
 }