Code optimization

This commit is contained in:
sunkaixuan
2017-08-25 22:25:29 +08:00
parent e6e2222de2
commit 8ef0a3343f
17 changed files with 33 additions and 34 deletions

View File

@@ -115,7 +115,7 @@ namespace SqlSugar
.Where(ec => !dbColumns.Any(dc => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase))) .Where(ec => !dbColumns.Any(dc => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
.Where(ec => .Where(ec =>
dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName) dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName)
&& ((ec.Length != dc.Length && !PubMethod.GetUnderType(ec.PropertyInfo).IsEnum() && PubMethod.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) || && ((ec.Length != dc.Length && !UtilMethods.GetUnderType(ec.PropertyInfo).IsEnum() && UtilMethods.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) ||
ec.IsNullable != dc.IsNullable || ec.IsNullable != dc.IsNullable ||
IsSamgeType(ec, dc)))).ToList(); IsSamgeType(ec, dc)))).ToList();
var renameColumns = entityColumns var renameColumns = entityColumns
@@ -212,7 +212,7 @@ namespace SqlSugar
} }
protected virtual DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item) protected virtual DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
{ {
var propertyType = PubMethod.GetUnderType(item.PropertyInfo); var propertyType = UtilMethods.GetUnderType(item.PropertyInfo);
var result = new DbColumnInfo() var result = new DbColumnInfo()
{ {
TableId = entityInfo.Columns.IndexOf(item), TableId = entityInfo.Columns.IndexOf(item),
@@ -246,7 +246,7 @@ namespace SqlSugar
{ {
return ec.DataType != dc.DataType; return ec.DataType != dc.DataType;
} }
var propertyType = PubMethod.GetUnderType(ec.PropertyInfo); var propertyType = UtilMethods.GetUnderType(ec.PropertyInfo);
var properyTypeName = string.Empty; var properyTypeName = string.Empty;
if (propertyType.IsEnum()) if (propertyType.IsEnum())
{ {

View File

@@ -135,7 +135,7 @@ namespace SqlSugar
} }
else else
{ {
reval.Add((T)Convert.ChangeType(re.GetValue(0),PubMethod.GetUnderType(type))); reval.Add((T)Convert.ChangeType(re.GetValue(0),UtilMethods.GetUnderType(type)));
} }
} }
} }

View File

@@ -168,7 +168,7 @@ namespace SqlSugar
IDbBind bind = Context.Ado.DbBind; IDbBind bind = Context.Ado.DbBind;
bool isNullableType = false; bool isNullableType = false;
MethodInfo method = null; MethodInfo method = null;
Type bindPropertyType = PubMethod.GetUnderType(bindProperty, ref isNullableType); Type bindPropertyType = UtilMethods.GetUnderType(bindProperty, ref isNullableType);
string dbTypeName = DataRecord.GetDataTypeName(ordinal); string dbTypeName = DataRecord.GetDataTypeName(ordinal);
if (Regex.IsMatch(dbTypeName, @"\(.+\)")) if (Regex.IsMatch(dbTypeName, @"\(.+\)"))
{ {
@@ -299,7 +299,7 @@ namespace SqlSugar
var isAny = invalidTypes.Contains(bindProperyTypeName); var isAny = invalidTypes.Contains(bindProperyTypeName);
if (isAny) if (isAny)
{ {
throw new SqlSugarException(string.Format("{0} can't convert {1} to {2}", propertyName, validPropertyType, bindProperyTypeName)); throw new UtilExceptions(string.Format("{0} can't convert {1} to {2}", propertyName, validPropertyType, bindProperyTypeName));
} }
} }
#endregion #endregion

View File

@@ -189,7 +189,7 @@ namespace SqlSugar
#region Sqlite Extensions #region Sqlite Extensions
public static Nullable<T> GetSqliteTypeNull<T>(this IDataReader dr, int i) where T : struct public static Nullable<T> GetSqliteTypeNull<T>(this IDataReader dr, int i) where T : struct
{ {
var type = PubMethod.GetUnderType(typeof(T)); var type = UtilMethods.GetUnderType(typeof(T));
if (dr.IsDBNull(i)) if (dr.IsDBNull(i))
{ {
return null; return null;

View File

@@ -174,7 +174,7 @@ namespace SqlSugar
Value = column.PropertyInfo.GetValue(item, null), Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName), DbColumnName = GetDbColumnName(column.PropertyName),
PropertyName = column.PropertyName, PropertyName = column.PropertyName,
PropertyType = PubMethod.GetUnderType(column.PropertyInfo), PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i TableId = i
}; };
if (columnInfo.PropertyType.IsEnum()) if (columnInfo.PropertyType.IsEnum())

View File

@@ -23,7 +23,7 @@ namespace SqlSugar
{ {
get get
{ {
_WhereInfos = PubMethod.IsNullReturnNew(_WhereInfos); _WhereInfos = UtilMethods.IsNullReturnNew(_WhereInfos);
return _WhereInfos; return _WhereInfos;
} }
set { _WhereInfos = value; } set { _WhereInfos = value; }

View File

@@ -53,7 +53,7 @@ namespace SqlSugar
{ {
get get
{ {
_EasyJoinInfos = PubMethod.IsNullReturnNew(_EasyJoinInfos); _EasyJoinInfos = UtilMethods.IsNullReturnNew(_EasyJoinInfos);
return _EasyJoinInfos; return _EasyJoinInfos;
} }
set { _EasyJoinInfos = value; } set { _EasyJoinInfos = value; }
@@ -62,7 +62,7 @@ namespace SqlSugar
{ {
get get
{ {
_JoinQueryInfos = PubMethod.IsNullReturnNew(_JoinQueryInfos); _JoinQueryInfos = UtilMethods.IsNullReturnNew(_JoinQueryInfos);
return _JoinQueryInfos; return _JoinQueryInfos;
} }
set { _JoinQueryInfos = value; } set { _JoinQueryInfos = value; }
@@ -72,7 +72,7 @@ namespace SqlSugar
{ {
get get
{ {
_WhereInfos = PubMethod.IsNullReturnNew(_WhereInfos); _WhereInfos = UtilMethods.IsNullReturnNew(_WhereInfos);
return _WhereInfos; return _WhereInfos;
} }
set { _WhereInfos = value; } set { _WhereInfos = value; }

View File

@@ -20,7 +20,7 @@ namespace SqlSugar
{ {
get get
{ {
base._SqlQueryBuilder = PubMethod.IsNullReturnNew(base._SqlQueryBuilder); base._SqlQueryBuilder = UtilMethods.IsNullReturnNew(base._SqlQueryBuilder);
return base._SqlQueryBuilder; return base._SqlQueryBuilder;
} }
set { base._SqlQueryBuilder = value; } set { base._SqlQueryBuilder = value; }

View File

@@ -41,7 +41,7 @@ namespace SqlSugar
{ {
get get
{ {
_Sql = PubMethod.IsNullReturnNew(_Sql); _Sql = UtilMethods.IsNullReturnNew(_Sql);
return _Sql; return _Sql;
} }
set set
@@ -60,7 +60,7 @@ namespace SqlSugar
{ {
get get
{ {
_Parameters = PubMethod.IsNullReturnNew(_Parameters); _Parameters = UtilMethods.IsNullReturnNew(_Parameters);
return _Parameters; return _Parameters;
} }
set set

View File

@@ -179,7 +179,7 @@ namespace SqlSugar
Value = column.PropertyInfo.GetValue(item, null), Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName), DbColumnName = GetDbColumnName(column.PropertyName),
PropertyName = column.PropertyName, PropertyName = column.PropertyName,
PropertyType = PubMethod.GetUnderType(column.PropertyInfo), PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i TableId = i
}; };
if (columnInfo.PropertyType.IsEnum()) if (columnInfo.PropertyType.IsEnum())

View File

@@ -26,7 +26,7 @@ namespace SqlSugar
{ {
var result = new DbColumnInfo() var result = new DbColumnInfo()
{ {
DataType = this.Context.Ado.DbBind.GetDbTypeName(PubMethod.GetUnderType(item.PropertyInfo).Name), DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilMethods.GetUnderType(item.PropertyInfo).Name),
TableId = entityInfo.Columns.IndexOf(item), TableId = entityInfo.Columns.IndexOf(item),
DbColumnName = item.DbColumnName.IsValuable() ? item.DbColumnName : item.PropertyName, DbColumnName = item.DbColumnName.IsValuable() ? item.DbColumnName : item.PropertyName,
IsPrimarykey = item.IsPrimarykey, IsPrimarykey = item.IsPrimarykey,

View File

@@ -45,7 +45,7 @@ namespace SqlSugar
{ {
var result = new DbColumnInfo() var result = new DbColumnInfo()
{ {
DataType = this.Context.Ado.DbBind.GetDbTypeName(PubMethod.GetUnderType(item.PropertyInfo).Name), DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilMethods.GetUnderType(item.PropertyInfo).Name),
TableId = entityInfo.Columns.IndexOf(item), TableId = entityInfo.Columns.IndexOf(item),
DbColumnName = item.DbColumnName.IsValuable() ? item.DbColumnName : item.PropertyName, DbColumnName = item.DbColumnName.IsValuable() ? item.DbColumnName : item.PropertyName,
IsPrimarykey = item.IsPrimarykey, IsPrimarykey = item.IsPrimarykey,

View File

@@ -140,9 +140,9 @@
<Compile Include="Utilities\ErrorMessage.cs" /> <Compile Include="Utilities\ErrorMessage.cs" />
<Compile Include="Utilities\IsWhatExtensions.cs" /> <Compile Include="Utilities\IsWhatExtensions.cs" />
<Compile Include="Utilities\UtilConstants.cs" /> <Compile Include="Utilities\UtilConstants.cs" />
<Compile Include="Utilities\UtilsConvert.cs" /> <Compile Include="Utilities\UtilConvert.cs" />
<Compile Include="Utilities\PubMethod.cs" /> <Compile Include="Utilities\UtilMethods.cs" />
<Compile Include="Utilities\SqlException.cs" /> <Compile Include="Utilities\UtilExceptions.cs" />
<Compile Include="Infrastructure\RewritableMethods.cs" /> <Compile Include="Infrastructure\RewritableMethods.cs" />
<Compile Include="Realization\SqlServer\CodeFirst\SqlServerCodeFirst.cs" /> <Compile Include="Realization\SqlServer\CodeFirst\SqlServerCodeFirst.cs" />
<Compile Include="Realization\SqlServer\SqlBuilder\SqlServerUpdateBuilder.cs" /> <Compile Include="Realization\SqlServer\SqlBuilder\SqlServerUpdateBuilder.cs" />

View File

@@ -9,31 +9,31 @@ namespace SqlSugar
public static void ThrowNotSupportedException(string message) public static void ThrowNotSupportedException(string message)
{ {
message = message.IsNullOrEmpty() ? new NotSupportedException().Message : message; message = message.IsNullOrEmpty() ? new NotSupportedException().Message : message;
throw new SqlSugarException("SqlSugarException.NotSupportedException" + message); throw new UtilExceptions("SqlSugarException.NotSupportedException" + message);
} }
public static void ConnectionConfig(ConnectionConfig config) public static void ConnectionConfig(ConnectionConfig config)
{ {
if (config == null || config.ConnectionString.IsNullOrEmpty() || config.DbType.IsNullOrEmpty()) if (config == null || config.ConnectionString.IsNullOrEmpty() || config.DbType.IsNullOrEmpty())
{ {
throw new SqlSugarException("SqlSugarException.ArgumentNullException" + ErrorMessage.ConnectionConfigIsNull); throw new UtilExceptions("SqlSugarException.ArgumentNullException" + ErrorMessage.ConnectionConfigIsNull);
} }
} }
public static void ArgumentNullException(object checkObj, string message) public static void ArgumentNullException(object checkObj, string message)
{ {
if (checkObj == null) if (checkObj == null)
throw new SqlSugarException("SqlSugarException.ArgumentNullException" + message); throw new UtilExceptions("SqlSugarException.ArgumentNullException" + message);
} }
public static void ArgumentNullException(object [] checkObj, string message) public static void ArgumentNullException(object [] checkObj, string message)
{ {
if (checkObj == null|| checkObj.Length==0) if (checkObj == null|| checkObj.Length==0)
throw new SqlSugarException("SqlSugarException.ArgumentNullException" + message); throw new UtilExceptions("SqlSugarException.ArgumentNullException" + message);
} }
public static void Exception(bool isException, string message, params string[] args) public static void Exception(bool isException, string message, params string[] args)
{ {
if (isException) if (isException)
throw new SqlSugarException(string.Format(message, args)); throw new UtilExceptions(string.Format(message, args));
} }
} }

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
namespace SqlSugar namespace SqlSugar
{ {
public static class UtilsConvert public static class UtilConvert
{ {
public static int ObjToInt(this object thisValue) public static int ObjToInt(this object thisValue)
{ {

View File

@@ -5,18 +5,18 @@ using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace SqlSugar namespace SqlSugar
{ {
public class SqlSugarException : Exception public class UtilExceptions : Exception
{ {
public SqlSugarException(string message) public UtilExceptions(string message)
: base(message){} : base(message){}
public SqlSugarException(SqlSugarClient context,string message, string sql) public UtilExceptions(SqlSugarClient context,string message, string sql)
: base(GetMessage(context, message, sql)) {} : base(GetMessage(context, message, sql)) {}
public SqlSugarException(SqlSugarClient context, string message, string sql, object pars) public UtilExceptions(SqlSugarClient context, string message, string sql, object pars)
: base(GetMessage(context,message, sql, pars)){} : base(GetMessage(context,message, sql, pars)){}
public SqlSugarException(SqlSugarClient context, string message, object pars) public UtilExceptions(SqlSugarClient context, string message, object pars)
: base(GetMessage(context,message, pars)){} : base(GetMessage(context,message, pars)){}
private static string GetMessage(SqlSugarClient context, string message, object pars) private static string GetMessage(SqlSugarClient context, string message, object pars)

View File

@@ -7,7 +7,7 @@ using System.Reflection;
using System.Text; using System.Text;
namespace SqlSugar namespace SqlSugar
{ {
public class PubMethod public class UtilMethods
{ {
internal static Type GetUnderType(Type oldType) internal static Type GetUnderType(Type oldType)
{ {
@@ -36,7 +36,6 @@ namespace SqlSugar
return unType != null; return unType != null;
} }
internal static T IsNullReturnNew<T>(T returnObj) where T : new() internal static T IsNullReturnNew<T>(T returnObj) where T : new()
{ {
if (returnObj.IsNullOrEmpty()) if (returnObj.IsNullOrEmpty())