예제 #1
0
        protected override string CreateContent(FormInfo formInfo)
        {
            MyStringBuilder fieldBuilder = new MyStringBuilder(256);

            foreach (TableInfo tableInfo in _tableInfos)
            {
                string columnDescription = tableInfo.ColumnDescription;
                string keyString         = null;
                string typeName          = ChangeToCSharpType(tableInfo.ColumnType);
                string name = tableInfo.ColumnName;
                name = name.Substring(0, 1).ToUpper() + name.Substring(1);
                string isNullable = tableInfo.IsNullable == "1" && typeName != "string" ? "?" : "";
                if (tableInfo.IsIncrement == "1")
                {
                    keyString = "[Key]";
                }
                fieldBuilder.AppendLine();
                fieldBuilder.AppendLine(2, "/// <summary>");
                fieldBuilder.AppendLine(2, $"/// {columnDescription}");
                fieldBuilder.AppendLine(2, "/// </summary>");
                if (string.IsNullOrWhiteSpace(keyString) == false)
                {
                    fieldBuilder.AppendLine(2, keyString);
                }
                fieldBuilder.AppendLine(2, "public " + typeName + isNullable + " " + name + " { " + "get; set;" + " }");
                fieldBuilder.AppendLine();
            }

            string[]        textArray = File.ReadAllLines(GetTemplateFromPath());
            MyStringBuilder sb        = new MyStringBuilder(128);

            foreach (string text in textArray)
            {
                string item = text.Replace(TemplatePlaceholder.NameSpaceName, formInfo.NameSpaceName).Replace(TemplatePlaceholder.TableName, formInfo.TableName);
                if (item.Trim() == TemplatePlaceholder.FieldArea)
                {
                    string temp = item.Replace(item, fieldBuilder.ToString());
                    sb.AppendLine(temp);
                }
                else
                {
                    sb.AppendLine(item);
                }
            }

            return(sb.ToString());
        }