private void CreateFile(string tableName, string tableComments, DataTable dt) { Output = Output ?? "Output"; string func; var modelName = GetClassName(tableName, out func); var className = string.Concat(modelName, Suffix); StringBuilder sb = new StringBuilder(); sb.AppendLine(Using.Replace("[Function]", func)); sb.AppendLine(); sb.Append("namespace "); sb.Append(Namespace); if (!string.IsNullOrEmpty(func)) { sb.Append("."); sb.Append(func); } sb.AppendLine(); sb.AppendLine("{"); sb.Append("\t// 添加 "); sb.Append(Environment.UserName); sb.Append(" "); sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd")); sb.AppendLine("\t/// <summary>"); sb.Append("\t/// ("); sb.Append(tableName.ToLower()); sb.AppendLine(")实体类"); if (!string.IsNullOrEmpty(tableComments)) { sb.Append("\t/// "); sb.AppendLine(tableComments); } sb.AppendLine("\t/// </summary>"); sb.Append("\tpublic"); if (!string.IsNullOrEmpty(ClassType)) { sb.Append(" "); sb.Append(ClassType); } sb.Append(" class "); sb.Append(className); if (!string.IsNullOrEmpty(Inherit)) { sb.Append(" : "); sb.Append(Inherit.Replace("[ModelName]", modelName)); } sb.AppendLine(); sb.AppendLine("\t{"); CreateFile(tableName, tableComments, dt, sb, className, modelName); sb.AppendLine("\t}"); sb.AppendLine("}"); if (!Directory.Exists(Path.Combine(Output, func))) { Directory.CreateDirectory(Path.Combine(Output, func)); } File.WriteAllText(Path.Combine(Output, func, className + ".cs"), sb.ToString(), Encoding.UTF8); Console.WriteLine("成功创建文件:{0}.cs", className); sb.Clear(); }