mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 22:25:49 +08:00
Code optimization
This commit is contained in:
@@ -22,7 +22,7 @@ namespace SqlSugar
|
||||
if (parameters != null)
|
||||
{
|
||||
var entityType = parameters.GetType();
|
||||
var isDictionary = entityType.IsIn(PubConst.DicArraySO, PubConst.DicArraySS);
|
||||
var isDictionary = entityType.IsIn(UtilConstants.DicArraySO, UtilConstants.DicArraySS);
|
||||
if (isDictionary)
|
||||
{
|
||||
DictionaryToParameters(parameters, sqlParameterKeyWord, result, entityType);
|
||||
@@ -69,7 +69,7 @@ namespace SqlSugar
|
||||
}
|
||||
protected void DictionaryToParameters(object parameters, string sqlParameterKeyWord, List<SugarParameter> listParams, Type entityType)
|
||||
{
|
||||
if (entityType == PubConst.DicArraySO)
|
||||
if (entityType == UtilConstants.DicArraySO)
|
||||
{
|
||||
var dictionaryParameters = (Dictionary<string, object>)parameters;
|
||||
var sugarParameters = dictionaryParameters.Select(it => new SugarParameter(sqlParameterKeyWord + it.Key, it.Value));
|
||||
|
||||
@@ -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.DbColumnName)
|
||||
&& ((ec.Length != dc.Length && !PubMethod.GetUnderType(ec.PropertyInfo).IsEnum() && PubMethod.GetUnderType(ec.PropertyInfo).IsIn(PubConst.StringType)) ||
|
||||
&& ((ec.Length != dc.Length && !PubMethod.GetUnderType(ec.PropertyInfo).IsEnum() && PubMethod.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) ||
|
||||
ec.IsNullable != dc.IsNullable ||
|
||||
IsSamgeType(ec, dc)))).ToList();
|
||||
var renameColumns = entityColumns
|
||||
@@ -231,7 +231,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (propertyType.IsEnum())
|
||||
{
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? PubConst.LongType.Name : PubConst.IntType.Name);
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -250,7 +250,7 @@ namespace SqlSugar
|
||||
var properyTypeName = string.Empty;
|
||||
if (propertyType.IsEnum())
|
||||
{
|
||||
properyTypeName = this.Context.Ado.DbBind.GetDbTypeName(ec.Length > 9 ? PubConst.LongType.Name : PubConst.IntType.Name);
|
||||
properyTypeName = this.Context.Ado.DbBind.GetDbTypeName(ec.Length > 9 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -45,32 +45,32 @@ namespace SqlSugar
|
||||
{
|
||||
while (re.Read())
|
||||
{
|
||||
if (PubConst.DicOO == type)
|
||||
if (UtilConstants.DicOO == type)
|
||||
{
|
||||
var kv = new KeyValuePair<object, object>(dataReader.GetValue(0), re.GetValue(1));
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<object, object>)));
|
||||
}
|
||||
else if (PubConst.DicIS == type)
|
||||
else if (UtilConstants.DicIS == type)
|
||||
{
|
||||
var kv = new KeyValuePair<int, string>(dataReader.GetValue(0).ObjToInt(), re.GetValue(1).ObjToString());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, string>)));
|
||||
}
|
||||
else if (PubConst.Dicii == type)
|
||||
else if (UtilConstants.Dicii == type)
|
||||
{
|
||||
var kv = new KeyValuePair<int, int>(dataReader.GetValue(0).ObjToInt(), re.GetValue(1).ObjToInt());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, int>)));
|
||||
}
|
||||
else if (PubConst.DicSi == type)
|
||||
else if (UtilConstants.DicSi == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, int>(dataReader.GetValue(0).ObjToString(), re.GetValue(1).ObjToInt());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, int>)));
|
||||
}
|
||||
else if (PubConst.DicSo == type)
|
||||
else if (UtilConstants.DicSo == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, object>(dataReader.GetValue(0).ObjToString(), re.GetValue(1));
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, object>)));
|
||||
}
|
||||
else if (PubConst.DicSS == type)
|
||||
else if (UtilConstants.DicSS == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, string>(dataReader.GetValue(0).ObjToString(), dataReader.GetValue(1).ObjToString());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, string>)));
|
||||
@@ -98,21 +98,21 @@ namespace SqlSugar
|
||||
{
|
||||
array[i] = Convert.ChangeType(re.GetValue(i), childType);
|
||||
}
|
||||
if (childType == PubConst.StringType)
|
||||
if (childType == UtilConstants.StringType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToString()).ToArray(), type));
|
||||
else if (childType == PubConst.ObjType)
|
||||
else if (childType == UtilConstants.ObjType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? null : (object)it).ToArray(), type));
|
||||
else if (childType == PubConst.BoolType)
|
||||
else if (childType == UtilConstants.BoolType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToBool()).ToArray(), type));
|
||||
else if (childType == PubConst.ByteType)
|
||||
else if (childType == UtilConstants.ByteType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? 0 : (byte)it).ToArray(), type));
|
||||
else if (childType == PubConst.DecType)
|
||||
else if (childType == UtilConstants.DecType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToDecimal()).ToArray(), type));
|
||||
else if (childType == PubConst.GuidType)
|
||||
else if (childType == UtilConstants.GuidType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? Guid.Empty : (Guid)it).ToArray(), type));
|
||||
else if (childType == PubConst.DateType)
|
||||
else if (childType == UtilConstants.DateType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? DateTime.MinValue : (DateTime)it).ToArray(), type));
|
||||
else if (childType == PubConst.IntType)
|
||||
else if (childType == UtilConstants.IntType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToInt()).ToArray(), type));
|
||||
else
|
||||
Check.Exception(true, ErrorMessage.NotSupportedArray);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace SqlSugar
|
||||
#region Public methods
|
||||
public virtual string GetDbTypeName(string csharpTypeName)
|
||||
{
|
||||
if (csharpTypeName == PubConst.ByteArrayType.Name)
|
||||
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
|
||||
{
|
||||
return "varbinary";
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace SqlSugar
|
||||
{
|
||||
return GetKeyValueList<T>(type, dataReader);
|
||||
}
|
||||
else if (type.IsValueType() || type == PubConst.StringType)
|
||||
else if (type.IsValueType() || type == UtilConstants.StringType)
|
||||
{
|
||||
return GetValueTypeList<T>(type, dataReader);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace SqlSugar
|
||||
}
|
||||
if (propertyInfo != null && propertyInfo.GetSetMethod() != null)
|
||||
{
|
||||
if (propertyInfo.PropertyType.IsClass() && propertyInfo.PropertyType != PubConst.ByteArrayType)
|
||||
if (propertyInfo.PropertyType.IsClass() && propertyInfo.PropertyType != UtilConstants.ByteArrayType)
|
||||
{
|
||||
BindClass(generator, result, propertyInfo);
|
||||
}
|
||||
@@ -186,15 +186,15 @@ namespace SqlSugar
|
||||
{
|
||||
method = isNullableType ? getConvertEnum_Null.MakeGenericMethod(bindPropertyType) : getEnum.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
else if (bindPropertyType == PubConst.IntType)
|
||||
else if (bindPropertyType == UtilConstants.IntType)
|
||||
{
|
||||
method = isNullableType ? getConvertInt32 : getInt32;
|
||||
}
|
||||
else if (bindPropertyType == PubConst.StringType)
|
||||
else if (bindPropertyType == UtilConstants.StringType)
|
||||
{
|
||||
method = getString;
|
||||
}
|
||||
else if (bindPropertyType == PubConst.ByteArrayType)
|
||||
else if (bindPropertyType == UtilConstants.ByteArrayType)
|
||||
{
|
||||
method = getValueMethod;
|
||||
generator.Emit(OpCodes.Call, method);
|
||||
@@ -280,7 +280,7 @@ namespace SqlSugar
|
||||
method = getValueMethod;
|
||||
break;
|
||||
}
|
||||
if (method == null && bindPropertyType == PubConst.StringType)
|
||||
if (method == null && bindPropertyType == UtilConstants.StringType)
|
||||
{
|
||||
method = getConvertString;
|
||||
}
|
||||
|
||||
@@ -205,27 +205,27 @@ namespace SqlSugar
|
||||
|
||||
private static T SqliteTypeConvert<T>(IDataReader dr, int i, Type type) where T : struct
|
||||
{
|
||||
if (type.IsIn(PubConst.IntType))
|
||||
if (type.IsIn(UtilConstants.IntType))
|
||||
{
|
||||
return (T)((object)(dr.GetInt32(i)));
|
||||
}
|
||||
else if (type == PubConst.DateType)
|
||||
else if (type == UtilConstants.DateType)
|
||||
{
|
||||
return (T)Convert.ChangeType(Convert.ToDateTime(dr.GetString(i)), type);
|
||||
}
|
||||
else if (type == PubConst.DecType)
|
||||
else if (type == UtilConstants.DecType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetDecimal(i), type);
|
||||
}
|
||||
else if (type == PubConst.DobType)
|
||||
else if (type == UtilConstants.DobType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetDouble(i), type);
|
||||
}
|
||||
else if (type == PubConst.BoolType)
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return (T)Convert.ChangeType(dr.GetBoolean(i), type);
|
||||
}
|
||||
else if (type == PubConst.GuidType)
|
||||
else if (type == UtilConstants.GuidType)
|
||||
{
|
||||
string guidString = dr.GetString(i);
|
||||
string changeValue = guidString.IsNullOrEmpty() ? Guid.Empty.ToString() : guidString;
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace SqlSugar
|
||||
}
|
||||
classText = classText.Replace(DbFirstTemplate.KeyClassName, className);
|
||||
classText = classText.Replace(DbFirstTemplate.KeyNamespace, this.Namespace);
|
||||
classText = classText.Replace(DbFirstTemplate.KeyUsing, IsAttribute ? (this.UsingTemplate + "using " + PubConst.AssemblyName + ";\r\n") : this.UsingTemplate);
|
||||
classText = classText.Replace(DbFirstTemplate.KeyUsing, IsAttribute ? (this.UsingTemplate + "using " + UtilConstants.AssemblyName + ";\r\n") : this.UsingTemplate);
|
||||
classText = classText.Replace(DbFirstTemplate.KeyClassDescription, this.ClassDescriptionTemplate.Replace(DbFirstTemplate.KeyClassDescription, tableInfo.Description + "\r\n"));
|
||||
classText = classText.Replace(DbFirstTemplate.KeySugarTable, IsAttribute ? string.Format(DbFirstTemplate.ValueSugarTable, tableInfo.Name) : null);
|
||||
if (columns.IsValuable())
|
||||
|
||||
@@ -84,14 +84,14 @@ namespace SqlSugar
|
||||
var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
|
||||
if (isFirst)
|
||||
{
|
||||
orString.Append(DeleteBuilder.WhereInOrTemplate + PubConst.Space);
|
||||
orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
|
||||
}
|
||||
int i = 0;
|
||||
StringBuilder andString = new StringBuilder();
|
||||
foreach (var primaryField in primaryFields)
|
||||
{
|
||||
if (i == 0)
|
||||
andString.Append(DeleteBuilder.WhereInAndTemplate + PubConst.Space);
|
||||
andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
|
||||
var entityPropertyName = this.Context.EntityProvider.GetPropertyName<T>(primaryField);
|
||||
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
|
||||
var entityValue = columnInfo.PropertyInfo.GetValue(deleteObj, null);
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace SqlSugar
|
||||
public virtual ISugarQueryable<T> Where<T2>(string whereString, object whereObj = null)
|
||||
{
|
||||
var whereValue = QueryBuilder.WhereInfos;
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString + PubConst.Space));
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString + UtilConstants.Space));
|
||||
if (whereObj != null)
|
||||
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
return this;
|
||||
@@ -577,7 +577,7 @@ namespace SqlSugar
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
OrderBy(lamResult.GetResultString() + PubConst.Space + type.ToString().ToUpper());
|
||||
OrderBy(lamResult.GetResultString() + UtilConstants.Space + type.ToString().ToUpper());
|
||||
return this;
|
||||
}
|
||||
protected ISugarQueryable<T> _GroupBy(Expression expression)
|
||||
@@ -729,7 +729,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (result.IsValuable())
|
||||
{
|
||||
if (entityType.GetTypeInfo().BaseType.IsValuable() && entityType.GetTypeInfo().BaseType == PubConst.ModelType)
|
||||
if (entityType.GetTypeInfo().BaseType.IsValuable() && entityType.GetTypeInfo().BaseType == UtilConstants.ModelType)
|
||||
{
|
||||
foreach (var item in result)
|
||||
{
|
||||
|
||||
@@ -83,10 +83,10 @@ namespace SqlSugar
|
||||
get
|
||||
{
|
||||
var result = Builder.GetTranslationTableName(EntityInfo.EntityName);
|
||||
result += PubConst.Space;
|
||||
result += UtilConstants.Space;
|
||||
if (this.TableWithString.IsValuable())
|
||||
{
|
||||
result += TableWithString + PubConst.Space;
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace SqlSugar
|
||||
{
|
||||
var isFirst = i == 0;
|
||||
whereString += isFirst ? "WHERE " : "AND ";
|
||||
whereString += (item + PubConst.Space);
|
||||
whereString += (item + UtilConstants.Space);
|
||||
++i;
|
||||
}
|
||||
return whereString;
|
||||
|
||||
@@ -86,10 +86,10 @@ namespace SqlSugar
|
||||
get
|
||||
{
|
||||
var result = Builder.GetTranslationTableName(EntityInfo.EntityName);
|
||||
result += PubConst.Space;
|
||||
result += UtilConstants.Space;
|
||||
if (this.TableWithString.IsValuable())
|
||||
{
|
||||
result += TableWithString + PubConst.Space;
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (type == PubConst.DateType)
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
@@ -169,11 +169,11 @@ namespace SqlSugar
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
else if (type == PubConst.BoolType)
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else if (type == PubConst.StringType || type == PubConst.ObjType)
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + value.ToString().ToSqlFilter() + "'";
|
||||
}
|
||||
|
||||
@@ -314,9 +314,9 @@ namespace SqlSugar
|
||||
{
|
||||
return string.Format(
|
||||
this.JoinTemplate,
|
||||
joinInfo.JoinType.ToString() + PubConst.Space,
|
||||
Builder.GetTranslationTableName(joinInfo.TableName) + PubConst.Space,
|
||||
joinInfo.ShortName + PubConst.Space + joinInfo.TableWithString,
|
||||
joinInfo.JoinType.ToString() + UtilConstants.Space,
|
||||
Builder.GetTranslationTableName(joinInfo.TableName) + UtilConstants.Space,
|
||||
joinInfo.ShortName + UtilConstants.Space + joinInfo.TableWithString,
|
||||
joinInfo.JoinWhere);
|
||||
}
|
||||
public virtual void Clear()
|
||||
@@ -392,7 +392,7 @@ namespace SqlSugar
|
||||
if (this.WhereInfos == null) return null;
|
||||
else
|
||||
{
|
||||
return string.Join(PubConst.Space, this.WhereInfos);
|
||||
return string.Join(UtilConstants.Space, this.WhereInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -403,7 +403,7 @@ namespace SqlSugar
|
||||
if (this.JoinQueryInfos.IsNullOrEmpty()) return null;
|
||||
else
|
||||
{
|
||||
return string.Join(PubConst.Space, this.JoinQueryInfos.Select(it => this.ToJoinString(it)));
|
||||
return string.Join(UtilConstants.Space, this.JoinQueryInfos.Select(it => this.ToJoinString(it)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,18 +412,18 @@ namespace SqlSugar
|
||||
get
|
||||
{
|
||||
var result = Builder.GetTranslationTableName(EntityName);
|
||||
result += PubConst.Space;
|
||||
result += UtilConstants.Space;
|
||||
if (this.TableWithString.IsValuable())
|
||||
{
|
||||
result += TableWithString + PubConst.Space;
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
if (this.TableShortName.IsValuable())
|
||||
{
|
||||
result += (TableShortName + PubConst.Space);
|
||||
result += (TableShortName + UtilConstants.Space);
|
||||
}
|
||||
if (!this.IsSingle())
|
||||
{
|
||||
result += GetJoinValueString + PubConst.Space;
|
||||
result += GetJoinValueString + UtilConstants.Space;
|
||||
}
|
||||
if (this.EasyJoinInfos.IsValuable())
|
||||
{
|
||||
@@ -459,7 +459,7 @@ namespace SqlSugar
|
||||
if (this.GroupByValue == null) return null;
|
||||
if (this.GroupByValue.Last() != ' ' )
|
||||
{
|
||||
return this.GroupByValue + PubConst.Space;
|
||||
return this.GroupByValue + UtilConstants.Space;
|
||||
}
|
||||
return this.GroupByValue;
|
||||
}
|
||||
|
||||
@@ -92,10 +92,10 @@ namespace SqlSugar
|
||||
get
|
||||
{
|
||||
var result = Builder.GetTranslationTableName(TableName);
|
||||
result += PubConst.Space;
|
||||
result += UtilConstants.Space;
|
||||
if (this.TableWithString.IsValuable())
|
||||
{
|
||||
result += TableWithString + PubConst.Space;
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -250,7 +250,7 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (type == PubConst.DateType)
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
@@ -263,11 +263,11 @@ namespace SqlSugar
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
else if (type == PubConst.BoolType)
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else if (type == PubConst.StringType || type == PubConst.ObjType)
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + value.ToString().ToSqlFilter() + "'";
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace SqlSugar
|
||||
FieldInfo field = (FieldInfo)memberExpr.Member;
|
||||
Check.Exception(field.IsPrivate, string.Format(" Field \"{0}\" can't be private ", field.Name));
|
||||
reval = field.GetValue(memberExpr.Member);
|
||||
if (reval != null && reval.GetType().IsClass() && reval.GetType() != PubConst.StringType)
|
||||
if (reval != null && reval.GetType().IsClass() && reval.GetType() != UtilConstants.StringType)
|
||||
{
|
||||
var fieldName = memberExpr.Member.Name;
|
||||
var proInfo = reval.GetType().GetProperty(fieldName);
|
||||
@@ -190,7 +190,7 @@ namespace SqlSugar
|
||||
object reval = null;
|
||||
PropertyInfo pro = (PropertyInfo)memberExpr.Member;
|
||||
reval = pro.GetValue(memberExpr.Member, null);
|
||||
if (reval != null && reval.GetType().IsClass() && reval.GetType() != PubConst.StringType)
|
||||
if (reval != null && reval.GetType().IsClass() && reval.GetType() != UtilConstants.StringType)
|
||||
{
|
||||
var fieldName = memberExpr.Member.Name;
|
||||
var proInfo = reval.GetType().GetProperty(fieldName);
|
||||
@@ -214,7 +214,7 @@ namespace SqlSugar
|
||||
public static object DynamicInvoke(Expression expression,MemberExpression memberExpression=null)
|
||||
{
|
||||
object value = Expression.Lambda(expression).Compile().DynamicInvoke();
|
||||
if (value != null && value.GetType().IsClass() && value.GetType() != PubConst.StringType&& memberExpression!=null)
|
||||
if (value != null && value.GetType().IsClass() && value.GetType() != UtilConstants.StringType&& memberExpression!=null)
|
||||
{
|
||||
value = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
|
||||
}
|
||||
@@ -233,7 +233,7 @@ namespace SqlSugar
|
||||
|
||||
public static bool IsEntity(Type type)
|
||||
{
|
||||
return type.IsClass() && type != PubConst.StringType;
|
||||
return type.IsClass() && type != UtilConstants.StringType;
|
||||
}
|
||||
|
||||
public static bool IsValueType(Type type)
|
||||
|
||||
@@ -27,47 +27,47 @@ namespace SqlSugar
|
||||
|
||||
private void SettingDataType(Type type)
|
||||
{
|
||||
if (type == PubConst.ByteArrayType)
|
||||
if (type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Binary;
|
||||
}
|
||||
else if (type == PubConst.GuidType)
|
||||
else if (type == UtilConstants.GuidType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Guid;
|
||||
}
|
||||
else if (type == PubConst.IntType)
|
||||
else if (type == UtilConstants.IntType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Int32;
|
||||
}
|
||||
else if (type == PubConst.ShortType)
|
||||
else if (type == UtilConstants.ShortType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Int16;
|
||||
}
|
||||
else if (type == PubConst.LongType)
|
||||
else if (type == UtilConstants.LongType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Int64;
|
||||
}
|
||||
else if (type == PubConst.DateType)
|
||||
else if (type == UtilConstants.DateType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.DateTime;
|
||||
}
|
||||
else if (type == PubConst.DobType)
|
||||
else if (type == UtilConstants.DobType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Double;
|
||||
}
|
||||
else if (type == PubConst.DecType)
|
||||
else if (type == UtilConstants.DecType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Decimal;
|
||||
}
|
||||
else if (type == PubConst.ByteType)
|
||||
else if (type == UtilConstants.ByteType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Byte;
|
||||
}
|
||||
else if (type == PubConst.FloatType)
|
||||
else if (type == UtilConstants.FloatType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Single;
|
||||
}
|
||||
else if (type == PubConst.BoolType)
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Boolean;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (_Size == 0 && Value != null)
|
||||
{
|
||||
var isByteArray = Value.GetType() == PubConst.ByteArrayType;
|
||||
var isByteArray = Value.GetType() == UtilConstants.ByteArrayType;
|
||||
if (isByteArray)
|
||||
_Size = -1;
|
||||
else
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace SqlSugar
|
||||
{
|
||||
var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
|
||||
var parentIsRoot = parameter.BaseParameter.CurrentExpression is LambdaExpression;
|
||||
var isBool = value != null && value.GetType() == PubConst.BoolType;
|
||||
var isBool = value != null && value.GetType() == UtilConstants.BoolType;
|
||||
if (parentIsRoot && isBool)
|
||||
{
|
||||
this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace SqlSugar
|
||||
var isSetTempData = baseParameter.CommonTempData.IsValuable() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
|
||||
var expression = base.Expression as MemberExpression;
|
||||
var isValue = expression.Member.Name == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
|
||||
var isBool = expression.Type == PubConst.BoolType;
|
||||
var isBool = expression.Type == UtilConstants.BoolType;
|
||||
var isValueBool = isValue && isBool && parameter.BaseExpression == null;
|
||||
var isLength = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == PubConst.StringType;
|
||||
var isDateValue = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == PubConst.DateType;
|
||||
var isLength = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == UtilConstants.StringType;
|
||||
var isDateValue = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == UtilConstants.DateType;
|
||||
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
|
||||
var isHasValue = isLogicOperator && expression.Member.Name == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess;
|
||||
if (isLength)
|
||||
@@ -144,7 +144,7 @@ namespace SqlSugar
|
||||
{
|
||||
fieldName = GetName(parameter, expression, isLeft, isSingle);
|
||||
}
|
||||
if (expression.Type == PubConst.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
|
||||
if (expression.Type == UtilConstants.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
|
||||
{
|
||||
fieldName = "( " + fieldName + "=1 )";
|
||||
}
|
||||
|
||||
@@ -161,10 +161,10 @@ namespace SqlSugar
|
||||
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
|
||||
var isConst = item is ConstantExpression;
|
||||
var isIIF= name == "IIF";
|
||||
var isIFFBoolMember = isIIF && (item is MemberExpression) && (item as MemberExpression).Type == PubConst.BoolType;
|
||||
var isIFFUnary = isIIF && (item is UnaryExpression) && (item as UnaryExpression).Operand.Type == PubConst.BoolType;
|
||||
var isIFFBoolBinary = isIIF && (item is BinaryExpression) && (item as BinaryExpression).Type == PubConst.BoolType;
|
||||
var isIFFBoolMethod = isIIF && (item is MethodCallExpression) && (item as MethodCallExpression).Type == PubConst.BoolType;
|
||||
var isIFFBoolMember = isIIF && (item is MemberExpression) && (item as MemberExpression).Type == UtilConstants.BoolType;
|
||||
var isIFFUnary = isIIF && (item is UnaryExpression) && (item as UnaryExpression).Operand.Type == UtilConstants.BoolType;
|
||||
var isIFFBoolBinary = isIIF && (item is BinaryExpression) && (item as BinaryExpression).Type == UtilConstants.BoolType;
|
||||
var isIFFBoolMethod = isIIF && (item is MethodCallExpression) && (item as MethodCallExpression).Type == UtilConstants.BoolType;
|
||||
var isFirst = item == args.First();
|
||||
if (isFirst && isIIF && isConst)
|
||||
{
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace SqlSugar
|
||||
Check.ThrowNotSupportedException(expression.ToString());
|
||||
break;
|
||||
case ResolveExpressType.SelectSingle:
|
||||
Check.Exception(expression.Type == PubConst.DateType, "ThrowNotSupportedException {0} ",expression.ToString());
|
||||
Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ",expression.ToString());
|
||||
Select(expression, parameter, true);
|
||||
break;
|
||||
case ResolveExpressType.SelectMultiple:
|
||||
Check.Exception(expression.Type == PubConst.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
|
||||
Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
|
||||
Select(expression, parameter, false);
|
||||
break;
|
||||
case ResolveExpressType.FieldSingle:
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace SqlSugar
|
||||
parameter.CommonTempData = null;
|
||||
}
|
||||
}
|
||||
else if (memberExpression.Type == PubConst.BoolType && isLogicOperator)
|
||||
else if (memberExpression.Type == UtilConstants.BoolType && isLogicOperator)
|
||||
{
|
||||
Append(parameter, nodeType);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class InstanceFactory
|
||||
{
|
||||
static Assembly assembly = Assembly.Load(PubConst.AssemblyName);
|
||||
static Assembly assembly = Assembly.Load(UtilConstants.AssemblyName);
|
||||
static Dictionary<string, Type> typeCache = new Dictionary<string, Type>();
|
||||
|
||||
#region Queryable
|
||||
@@ -202,7 +202,7 @@ namespace SqlSugar
|
||||
|
||||
private static string GetClassName(string type, string name)
|
||||
{
|
||||
return PubConst.AssemblyName + "." + type + name;
|
||||
return UtilConstants.AssemblyName + "." + type + name;
|
||||
}
|
||||
|
||||
#region CreateInstance
|
||||
|
||||
@@ -108,19 +108,19 @@ namespace SqlSugar
|
||||
var addValue = readerValues[name];
|
||||
if (addValue == DBNull.Value)
|
||||
{
|
||||
if (item.PropertyType.IsIn(PubConst.IntType, PubConst.DecType, PubConst.DobType, PubConst.ByteType))
|
||||
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
||||
{
|
||||
addValue = 0;
|
||||
}
|
||||
else if (item.PropertyType == PubConst.GuidType)
|
||||
else if (item.PropertyType == UtilConstants.GuidType)
|
||||
{
|
||||
addValue = Guid.Empty;
|
||||
}
|
||||
else if (item.PropertyType == PubConst.DateType)
|
||||
else if (item.PropertyType == UtilConstants.DateType)
|
||||
{
|
||||
addValue = DateTime.MinValue;
|
||||
}
|
||||
else if (item.PropertyType == PubConst.StringType)
|
||||
else if (item.PropertyType == UtilConstants.StringType)
|
||||
{
|
||||
addValue = null;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.PropertyType == PubConst.IntType)
|
||||
if (item.PropertyType == UtilConstants.IntType)
|
||||
{
|
||||
addValue = Convert.ToInt32(addValue);
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ namespace SqlSugar
|
||||
var index = 1;
|
||||
foreach (var item in entityTypeArray)
|
||||
{
|
||||
result.Add(PubConst.Space +lambdaParameters[index].Name, item.Name);
|
||||
result.Add(UtilConstants.Space +lambdaParameters[index].Name, item.Name);
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SqlSugar
|
||||
{
|
||||
public override string GetDbTypeName(string csharpTypeName)
|
||||
{
|
||||
if (csharpTypeName == PubConst.ByteArrayType.Name)
|
||||
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
|
||||
{
|
||||
return "blob";
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SqlSugar
|
||||
{
|
||||
public override string GetDbTypeName(string csharpTypeName)
|
||||
{
|
||||
if (csharpTypeName == PubConst.ByteArrayType.Name)
|
||||
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
|
||||
{
|
||||
return "blob";
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (type == PubConst.DateType)
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
@@ -56,11 +56,11 @@ namespace SqlSugar
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
else if (type == PubConst.BoolType)
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else if (type == PubConst.StringType || type == PubConst.ObjType)
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "'" + value.ToString().ToSqlFilter() + "'";
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (type == PubConst.DateType)
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < Convert.ToDateTime("1900-1-1"))
|
||||
@@ -33,11 +33,11 @@ namespace SqlSugar
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
else if (type == PubConst.BoolType)
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else if (type == PubConst.StringType || type == PubConst.ObjType)
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "'" + value.ToString().ToSqlFilter() + "'";
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@
|
||||
<Compile Include="Utilities\DbExtensions.cs" />
|
||||
<Compile Include="Utilities\ErrorMessage.cs" />
|
||||
<Compile Include="Utilities\IsWhatExtensions.cs" />
|
||||
<Compile Include="Utilities\PubConst.cs" />
|
||||
<Compile Include="Utilities\PubConvert.cs" />
|
||||
<Compile Include="Utilities\UtilConstants.cs" />
|
||||
<Compile Include="Utilities\UtilsConvert.cs" />
|
||||
<Compile Include="Utilities\PubMethod.cs" />
|
||||
<Compile Include="Utilities\SqlException.cs" />
|
||||
<Compile Include="Infrastructure\RewritableMethods.cs" />
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal static class PubConst
|
||||
internal static class UtilConstants
|
||||
{
|
||||
internal const string AssemblyName = "SqlSugar";
|
||||
internal const string Space = " ";
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public static class PubConvert
|
||||
public static class UtilsConvert
|
||||
{
|
||||
public static int ObjToInt(this object thisValue)
|
||||
{
|
||||
Reference in New Issue
Block a user