Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
bd7e2ff33f
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 9
      OrmTest/Program.cs
  3. BIN
      OrmTest/bin/Debug/OrmTest.exe
  4. BIN
      OrmTest/bin/Debug/OrmTest.pdb
  5. BIN
      OrmTest/bin/Debug/SqlSugar.dll
  6. BIN
      OrmTest/bin/Debug/SqlSugar.pdb
  7. BIN
      OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache
  8. BIN
      OrmTest/obj/Debug/OrmTest.exe
  9. BIN
      OrmTest/obj/Debug/OrmTest.pdb
  10. 0
      SqlSugar/ExpressionsToSql/Common/BinaryExpressionInfo.cs
  11. 0
      SqlSugar/ExpressionsToSql/Common/ExpResolveAccessory.cs
  12. 0
      SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs
  13. 0
      SqlSugar/ExpressionsToSql/Common/ExpressionErrorMessage.cs
  14. 0
      SqlSugar/ExpressionsToSql/Common/ExpressionParameter.cs
  15. 160
      SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs
  16. 0
      SqlSugar/ExpressionsToSql/Common/ResolveExpressType.cs
  17. 0
      SqlSugar/ExpressionsToSql/Common/SugarParameter.cs
  18. 48
      SqlSugar/ExpressionsToSql/ExpressionTool.cs
  19. 8
      SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  20. 119
      SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs
  21. 45
      SqlSugar/ExpressionsToSql/ResolveItems/MemberNoExpressionResolve.cs
  22. 17
      SqlSugar/SqlSugar.csproj
  23. BIN
      SqlSugar/bin/Debug/SqlSugar.dll
  24. BIN
      SqlSugar/bin/Debug/SqlSugar.pdb
  25. BIN
      SqlSugar/obj/Debug/SqlSugar.dll
  26. BIN
      SqlSugar/obj/Debug/SqlSugar.pdb

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

9
OrmTest/Program.cs

@ -14,12 +14,15 @@ namespace OrmTest
class Program
{
public string id { get; set;}
public static string GetName() {
return "a";
}
public static string id { get; set;}
static void Main(string[] args)
{
Program.id = "xx";
string x = "1";
Expression<Func<Student, bool>> exp = it => it.Name!=x;
Expression<Func<Student, bool>> exp = it => it.Name== GetName();
// Expression<Func<Student, object>> exp = it => it.Name;
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.Single);
// var x = expContext.GetFiledName();

BIN
OrmTest/bin/Debug/OrmTest.exe

Binary file not shown.

BIN
OrmTest/bin/Debug/OrmTest.pdb

Binary file not shown.

BIN
OrmTest/bin/Debug/SqlSugar.dll

Binary file not shown.

BIN
OrmTest/bin/Debug/SqlSugar.pdb

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.exe

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.pdb

Binary file not shown.

0
SqlSugar/ExpressionsToSql/BinaryExpressionInfo.cs → SqlSugar/ExpressionsToSql/Common/BinaryExpressionInfo.cs

0
SqlSugar/ExpressionsToSql/ExpResolveAccessory.cs → SqlSugar/ExpressionsToSql/Common/ExpResolveAccessory.cs

0
SqlSugar/ExpressionsToSql/ExpressionConst.cs → SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs

0
SqlSugar/ExpressionsToSql/ExpressionErrorMessage.cs → SqlSugar/ExpressionsToSql/Common/ExpressionErrorMessage.cs

0
SqlSugar/ExpressionsToSql/ExpressionParameter.cs → SqlSugar/ExpressionsToSql/Common/ExpressionParameter.cs

160
SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace SqlSugar
{
public class ExpressionTool
{
public static string GetOperator(ExpressionType expressiontype)
{
switch (expressiontype)
{
case ExpressionType.And:
case ExpressionType.AndAlso:
return " AND ";
case ExpressionType.Equal:
return " =";
case ExpressionType.GreaterThan:
return " >";
case ExpressionType.GreaterThanOrEqual:
return ">=";
case ExpressionType.LessThan:
return "<";
case ExpressionType.LessThanOrEqual:
return "<=";
case ExpressionType.NotEqual:
return "<>";
case ExpressionType.Or:
case ExpressionType.OrElse:
return " OR ";
case ExpressionType.Add:
case ExpressionType.AddChecked:
return "+";
case ExpressionType.Subtract:
case ExpressionType.SubtractChecked:
return "-";
case ExpressionType.Divide:
return "/";
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
return "*";
default:
throw new NotSupportedException(string.Format(ExpressionErrorMessage.OperatorError, expressiontype.ToString()));
}
}
public static object GetValue(MemberInfo member, Expression expression)
{
var memberInfos = new Stack<MemberInfo>();
var fieldInfo = member as System.Reflection.FieldInfo;
object reval = null;
// "descend" toward's the root object reference:
while (expression is MemberExpression)
{
var memberExpr = expression as MemberExpression;
memberInfos.Push(memberExpr.Member);
if (memberExpr.Expression == null)
{
var isProperty = memberExpr.Member.MemberType == MemberTypes.Property;
var isField = memberExpr.Member.MemberType == MemberTypes.Field;
if (isProperty)
{
reval = GetPropertyValue(memberExpr);
}
else if (isField)
{
reval = GetFiledValue(memberExpr);
}
}
if (memberExpr.Expression == null)
{
}
expression = memberExpr.Expression;
}
// fetch the root object reference:
var constExpr = expression as ConstantExpression;
object objReference = constExpr.Value;
// "ascend" back whence we came from and resolve object references along the way:
while (memberInfos.Count > 0) // or some other break condition
{
var mi = memberInfos.Pop();
if (mi.MemberType == MemberTypes.Property)
{
var objProp = objReference.GetType().GetProperty(mi.Name);
if (objProp == null)
{
}
objReference = objProp.GetValue(objReference, null);
}
else if (mi.MemberType == MemberTypes.Field)
{
var objField = objReference.GetType().GetField(mi.Name);
if (objField == null)
{
}
objReference = objField.GetValue(objReference);
}
}
reval = objReference;
return reval;
}
public static object GetFiledValue(MemberExpression memberExpr)
{
object reval = null;
FieldInfo field = (FieldInfo)memberExpr.Member;
reval = field.GetValue(memberExpr.Member);
if (reval != null && reval.GetType().IsClass && reval.GetType() != ExpressionConst.StringType)
{
var fieldName = memberExpr.Member.Name;
var proInfo = reval.GetType().GetProperty(fieldName);
if (proInfo != null)
{
reval = proInfo.GetValue(reval, null);
}
var fieInfo = reval.GetType().GetField(fieldName);
if (fieInfo != null)
{
reval = fieInfo.GetValue(reval);
}
if (fieInfo == null && proInfo == null)
{
}
}
return reval;
}
public static object GetPropertyValue(MemberExpression memberExpr)
{
object reval = null;
PropertyInfo pro = (PropertyInfo)memberExpr.Member;
reval = pro.GetValue(memberExpr.Member, null);
if (reval != null && reval.GetType().IsClass && reval.GetType() != ExpressionConst.StringType)
{
var fieldName = memberExpr.Member.Name;
var proInfo = reval.GetType().GetProperty(fieldName);
if (proInfo != null)
{
reval = proInfo.GetValue(reval, null);
}
var fieInfo = reval.GetType().GetField(fieldName);
if (fieInfo != null)
{
reval = fieInfo.GetValue(reval);
}
if (fieInfo == null && proInfo == null)
{
}
}
return reval;
}
}
}

0
SqlSugar/ExpressionsToSql/ResolveExpressType.cs → SqlSugar/ExpressionsToSql/Common/ResolveExpressType.cs

0
SqlSugar/ExpressionsToSql/SugarParameter.cs → SqlSugar/ExpressionsToSql/Common/SugarParameter.cs

48
SqlSugar/ExpressionsToSql/ExpressionTool.cs

@ -1,48 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class ExpressionTool
{
public static string GetOperator(ExpressionType expressiontype)
{
switch (expressiontype)
{
case ExpressionType.And:
case ExpressionType.AndAlso:
return " AND ";
case ExpressionType.Equal:
return " =";
case ExpressionType.GreaterThan:
return " >";
case ExpressionType.GreaterThanOrEqual:
return ">=";
case ExpressionType.LessThan:
return "<";
case ExpressionType.LessThanOrEqual:
return "<=";
case ExpressionType.NotEqual:
return "<>";
case ExpressionType.Or:
case ExpressionType.OrElse:
return " OR ";
case ExpressionType.Add:
case ExpressionType.AddChecked:
return "+";
case ExpressionType.Subtract:
case ExpressionType.SubtractChecked:
return "-";
case ExpressionType.Divide:
return "/";
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
return "*";
default:
throw new NotSupportedException(string.Format(ExpressionErrorMessage.OperatorError, expressiontype.ToString()));
}
}
}
}

8
SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -36,7 +36,7 @@ namespace SqlSugar
Expression = exp,
IsLeft = this.IsLeft,
BaseExpression = this.BaseExpression,
BaseParameter=this.BaseParameter,
BaseParameter = this.BaseParameter,
Index = this.Index
};
if (exp is LambdaExpression)
@ -59,7 +59,11 @@ namespace SqlSugar
{
return new MethodCallExpressionResolve(parameter);
}
else if (exp is MemberExpression&&((MemberExpression)exp).Expression.NodeType== ExpressionType.Constant)
else if (exp is MemberExpression && ((MemberExpression)exp).Expression == null)
{
return new MemberNoExpressionResolve(parameter);
}
else if (exp is MemberExpression && ((MemberExpression)exp).Expression.NodeType == ExpressionType.Constant)
{
return new MemberConstExpressionResolve(parameter);
}

119
SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs

@ -5,7 +5,6 @@ using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class MemberConstExpressionResolve : BaseResolve
@ -15,7 +14,7 @@ namespace SqlSugar
var expression = base.Expression as MemberExpression;
var isLeft = parameter.IsLeft;
var isSingle = parameter.Context.IsSingle;
object value = GetValue(expression.Member, expression);
object value = ExpressionTool.GetValue(expression.Member, expression);
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
@ -31,120 +30,6 @@ namespace SqlSugar
base.Context.SqlWhere.Append(value);
}
}
private object GetValue(MemberInfo member, Expression expression)
{
var memberInfos = new Stack<MemberInfo>();
var fieldInfo = member as System.Reflection.FieldInfo;
object reval = null;
// "descend" toward's the root object reference:
while (expression is MemberExpression)
{
var memberExpr = expression as MemberExpression;
memberInfos.Push(memberExpr.Member);
if (memberExpr.Expression == null)
{
var isProperty = memberExpr.Member.MemberType == MemberTypes.Property;
var isField = memberExpr.Member.MemberType == MemberTypes.Field;
if (isProperty)
{
reval = GetPropertyValue(memberExpr);
}
else if (isField)
{
reval = GetFiledValue(memberExpr);
}
}
if (memberExpr.Expression == null)
{
}
expression = memberExpr.Expression;
}
// fetch the root object reference:
var constExpr = expression as ConstantExpression;
if (constExpr == null)
{
}
var objReference = constExpr.Value;
// "ascend" back whence we came from and resolve object references along the way:
while (memberInfos.Count > 0) // or some other break condition
{
var mi = memberInfos.Pop();
if (mi.MemberType == MemberTypes.Property)
{
var objProp = objReference.GetType().GetProperty(mi.Name);
if (objProp == null)
{
}
objReference = objProp.GetValue(objReference, null);
}
else if (mi.MemberType == MemberTypes.Field)
{
var objField = objReference.GetType().GetField(mi.Name);
if (objField == null)
{
}
objReference = objField.GetValue(objReference);
}
}
reval = objReference;
return reval;
}
private static object GetFiledValue(MemberExpression memberExpr)
{
object reval = null;
FieldInfo field = (FieldInfo)memberExpr.Member;
reval = field.GetValue(memberExpr.Member);
if (reval != null && reval.GetType().IsClass && reval.GetType() != ExpressionConst.StringType)
{
var fieldName = memberExpr.Member.Name;
var proInfo = reval.GetType().GetProperty(fieldName);
if (proInfo != null)
{
reval = proInfo.GetValue(reval, null);
}
var fieInfo = reval.GetType().GetField(fieldName);
if (fieInfo != null)
{
reval = fieInfo.GetValue(reval);
}
if (fieInfo == null && proInfo == null)
{
}
}
return reval;
}
private static object GetPropertyValue(MemberExpression memberExpr)
{
object reval = null;
PropertyInfo pro = (PropertyInfo)memberExpr.Member;
reval = pro.GetValue(memberExpr.Member, null);
if (reval != null && reval.GetType().IsClass && reval.GetType() != ExpressionConst.StringType)
{
var fieldName = memberExpr.Member.Name;
var proInfo = reval.GetType().GetProperty(fieldName);
if (proInfo != null)
{
reval = proInfo.GetValue(reval, null);
}
var fieInfo = reval.GetType().GetField(fieldName);
if (fieInfo != null)
{
reval = fieInfo.GetValue(reval);
}
if (fieInfo == null && proInfo == null)
{
}
}
return reval;
}
}
}

45
SqlSugar/ExpressionsToSql/ResolveItems/MemberNoExpressionResolve.cs

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class MemberNoExpressionResolve : BaseResolve
{
public MemberNoExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
var expression = base.Expression as MemberExpression;
var isLeft = parameter.IsLeft;
var isSingle = parameter.Context.IsSingle;
object value = null;
var fieldInfo = expression.Member as System.Reflection.FieldInfo;
var propertyInfo = expression.Member as System.Reflection.PropertyInfo;
if (fieldInfo != null)
{
value = ExpressionTool.GetFiledValue(expression);
}
else if (propertyInfo != null)
{
value = ExpressionTool.GetPropertyValue(expression);
}
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(isLeft),
Value = value,
ExpressionType = ExpressionConst.ConstantExpressionType
}));
}
if (isLeft == null && base.Context.SqlWhere == null)
{
base.Context.SqlWhere = new StringBuilder();
base.Context.SqlWhere.Append(value);
}
}
}
}

17
SqlSugar/SqlSugar.csproj

@ -97,12 +97,13 @@
<Compile Include="Entities\ConnectionConfig.cs" />
<Compile Include="Entities\DbColumnInfo.cs" />
<Compile Include="Entities\DbTableInfo.cs" />
<Compile Include="ExpressionsToSql\BinaryExpressionInfo.cs" />
<Compile Include="ExpressionsToSql\ExpressionErrorMessage.cs" />
<Compile Include="ExpressionsToSql\Common\BinaryExpressionInfo.cs" />
<Compile Include="ExpressionsToSql\Common\ExpressionErrorMessage.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\MemberConstExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\MemberNewExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\SugarParameter.cs" />
<Compile Include="ExpressionsToSql\ExpressionParameter.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\MemberNoExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\Common\SugarParameter.cs" />
<Compile Include="ExpressionsToSql\Common\ExpressionParameter.cs" />
<Compile Include="Entities\JoinQueryInfo.cs" />
<Compile Include="Entities\Mapping\MappingColumn.cs" />
<Compile Include="Entities\Mapping\MappingTable.cs" />
@ -111,8 +112,8 @@
<Compile Include="Enum\ApplyType.cs" />
<Compile Include="Enum\JoinType.cs" />
<Compile Include="Enum\OrderByType.cs" />
<Compile Include="ExpressionsToSql\ResolveExpressType.cs" />
<Compile Include="ExpressionsToSql\ExpressionConst.cs" />
<Compile Include="ExpressionsToSql\Common\ResolveExpressType.cs" />
<Compile Include="ExpressionsToSql\Common\ExpressionConst.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\BaseResolve.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\BinaryExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\BlockExpressionResolve.cs" />
@ -122,9 +123,9 @@
<Compile Include="ExpressionsToSql\ResolveItems\MemberExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\MethodCallExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\UnaryExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpResolveAccessory.cs" />
<Compile Include="ExpressionsToSql\Common\ExpResolveAccessory.cs" />
<Compile Include="ExpressionsToSql\ExpressionContext.cs" />
<Compile Include="ExpressionsToSql\ExpressionTool.cs" />
<Compile Include="ExpressionsToSql\Common\ExpressionTool.cs" />
<Compile Include="InstanceFactory.cs" />
<Compile Include="Interface\ICodeFirst.cs" />
<Compile Include="Interface\IDb.cs" />

BIN
SqlSugar/bin/Debug/SqlSugar.dll

Binary file not shown.

BIN
SqlSugar/bin/Debug/SqlSugar.pdb

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.dll

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.pdb

Binary file not shown.
Loading…
Cancel
Save