Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
cca1d61fe0
  1. 16
      SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs
  2. 4
      SqlSugar/Abstract/DbFirstProvider/DefaultTemplate.cs
  3. 69
      SqlSugar/ExpressionsToSql/Common/FileHeper.cs
  4. 1
      SqlSugar/SqlSugar.csproj

16
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<SchemaInfo> GetSchemaInfoList
{

4
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}
/// </summary>\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;

69
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);
}
}
}

1
SqlSugar/SqlSugar.csproj

@ -64,6 +64,7 @@
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
<Compile Include="Entities\SchemaInfo.cs" />
<Compile Include="Enum\DbObjectType.cs" />
<Compile Include="ExpressionsToSql\Common\FileHeper.cs" />
<Compile Include="Interface\ICacheManager.cs" />
<Compile Include="Entities\SugarMessageResult.cs" />
<Compile Include="Enum\InitKeyType.cs" />

Loading…
Cancel
Save