From cca1d61fe0b180a33d51084cc692c14f3ad7e332 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 28 May 2017 22:19:35 +0800 Subject: [PATCH] - --- .../DbFirstProvider/DbFirstProvider.cs | 16 +++++ .../DbFirstProvider/DefaultTemplate.cs | 4 +- SqlSugar/ExpressionsToSql/Common/FileHeper.cs | 69 +++++++++++++++++++ SqlSugar/SqlSugar.csproj | 1 + 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 SqlSugar/ExpressionsToSql/Common/FileHeper.cs diff --git a/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs b/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs index 1b1764aee..163bec88a 100644 --- a/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs +++ b/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs @@ -7,6 +7,22 @@ namespace SqlSugar public abstract partial class DbFirstProvider : IDbFirst { public virtual SqlSugarClient Context { get; set; } + private string ClassTemplate { get; set; } + private string ClassDescriptionTemplate { get; set; } + private string PropertyTemplate { get; set; } + private string PropertyDescriptionTemplate { get; set; } + private string ConstructorTemplate { get; set; } + private string NamespaceTemplate { get; set; } + private string + + public DbFirstProvider() { + this.ClassTemplate = DefaultTemplate.ClassTemplate; + this.ClassDescriptionTemplate = DefaultTemplate.ClassDescriptionTemplate; + this.PropertyTemplate = DefaultTemplate.PropertyTemplate; + this.PropertyDescriptionTemplate = DefaultTemplate.PropertyDescriptionTemplate; + this.ConstructorTemplate = DefaultTemplate.ConstructorTemplate; + this.NamespaceTemplate = DefaultTemplate.NamespaceTemplate; + } public List GetSchemaInfoList { diff --git a/SqlSugar/Abstract/DbFirstProvider/DefaultTemplate.cs b/SqlSugar/Abstract/DbFirstProvider/DefaultTemplate.cs index 5bc3abf25..f8c07d9fe 100644 --- a/SqlSugar/Abstract/DbFirstProvider/DefaultTemplate.cs +++ b/SqlSugar/Abstract/DbFirstProvider/DefaultTemplate.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -namespace SqlSugar.Abstract.DbFirstProvider +namespace SqlSugar { public class DefaultTemplate { @@ -33,7 +33,7 @@ public {PropertyType} {PropertyName} {get;set;}\r\n"; /// Nullable:{IsNullable} /// \r\n"; - public static string ConstructorTemplate = @" this.$PropertyName =Convert.To$PropertyType(""{0}"")\r\n"; + public static string ConstructorTemplate = @" this.$PropertyName =Convert.To{PropertyType}(""{DefaultValue}"");\r\n"; public static string NamespaceTemplate = @"using System; using System.Linq; diff --git a/SqlSugar/ExpressionsToSql/Common/FileHeper.cs b/SqlSugar/ExpressionsToSql/Common/FileHeper.cs new file mode 100644 index 000000000..781038a06 --- /dev/null +++ b/SqlSugar/ExpressionsToSql/Common/FileHeper.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace SqlSugar +{ + public class FileHeper + { + public static void CreateFile(string filePath, string text, Encoding encoding) + { + try + { + if (IsExistFile(filePath)) + { + DeleteFile(filePath); + } + if (!IsExistFile(filePath)) + { + string directoryPath = GetDirectoryFromFilePath(filePath); + CreateDirectory(directoryPath); + + //Create File + FileInfo file = new FileInfo(filePath); + using (FileStream stream = file.Create()) + { + using (StreamWriter writer = new StreamWriter(stream, encoding)) + { + writer.Write(text); + writer.Flush(); + } + } + } + } + catch + { + } + } + public static bool IsExistDirectory(string directoryPath) + { + return Directory.Exists(directoryPath); + } + public static void CreateDirectory(string directoryPath) + { + if (!IsExistDirectory(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + } + public static void DeleteFile(string filePath) + { + if (IsExistFile(filePath)) + { + File.Delete(filePath); + } + } + public static string GetDirectoryFromFilePath(string filePath) + { + FileInfo file = new FileInfo(filePath); + DirectoryInfo directory = file.Directory; + return directory.FullName; + } + public static bool IsExistFile(string filePath) + { + return File.Exists(filePath); + } + } +} diff --git a/SqlSugar/SqlSugar.csproj b/SqlSugar/SqlSugar.csproj index a8db3fe8e..0a24fb4ec 100644 --- a/SqlSugar/SqlSugar.csproj +++ b/SqlSugar/SqlSugar.csproj @@ -64,6 +64,7 @@ +