Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
1b42ff5ce9
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 6
      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. 7
      SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  11. 100
      SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs
  12. 152
      SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs
  13. 16
      SqlSugar/ExpressionsToSql/ResolveItems/MemberNewExpressionResolve.cs
  14. 2
      SqlSugar/SqlSugar.csproj
  15. BIN
      SqlSugar/bin/Debug/SqlSugar.dll
  16. BIN
      SqlSugar/bin/Debug/SqlSugar.pdb
  17. BIN
      SqlSugar/obj/Debug/SqlSugar.dll
  18. BIN
      SqlSugar/obj/Debug/SqlSugar.pdb

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

6
OrmTest/Program.cs

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

7
SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -61,8 +61,11 @@ namespace SqlSugar
} }
else if (exp is MemberExpression&&((MemberExpression)exp).Expression.NodeType== ExpressionType.Constant) else if (exp is MemberExpression&&((MemberExpression)exp).Expression.NodeType== ExpressionType.Constant)
{ {
parameter.Expression = ((MemberExpression)exp).Expression; return new MemberConstExpressionResolve(parameter);
return new ConstantExpressionResolve(parameter); }
else if (exp is MemberExpression && ((MemberExpression)exp).Expression.NodeType == ExpressionType.New)
{
return new MemberNewExpressionResolve(parameter);
} }
else if (exp is ConstantExpression) else if (exp is ConstantExpression)
{ {

100
SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs

@ -29,105 +29,5 @@ namespace SqlSugar
base.Context.SqlWhere.Append(value); 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 dynInv = 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)
// {
// if (memberExpr.Member.MemberType == MemberTypes.Property)
// {
// PropertyInfo pro = (PropertyInfo)memberExpr.Member;
// dynInv = pro.GetValue(memberExpr.Member, null);
// if (dynInv != null && dynInv.GetType().IsClass)
// {
// var fieldName = memberExpr.Member.Name;
// var proInfo = dynInv.GetType().GetProperty(fieldName);
// if (proInfo != null)
// {
// dynInv = proInfo.GetValue(dynInv, null);
// }
// var fieInfo = dynInv.GetType().GetField(fieldName);
// if (fieInfo != null)
// {
// dynInv = fieInfo.GetValue(dynInv);
// }
// if (fieInfo == null && proInfo == null)
// {
// }
// }
// }
// else if (memberExpr.Member.MemberType == MemberTypes.Field)
// {
// FieldInfo field = (FieldInfo)memberExpr.Member;
// dynInv = field.GetValue(memberExpr.Member);
// if (dynInv != null && dynInv.GetType().IsClass && dynInv.GetType() != ExpressionConst.StringType)
// {
// var fieldName = memberExpr.Member.Name;
// var proInfo = dynInv.GetType().GetProperty(fieldName);
// if (proInfo != null)
// {
// dynInv = proInfo.GetValue(dynInv, null);
// }
// var fieInfo = dynInv.GetType().GetField(fieldName);
// if (fieInfo != null)
// {
// dynInv = fieInfo.GetValue(dynInv);
// }
// if (fieInfo == null && proInfo == null)
// {
// }
// }
// }
// }
// 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);
// }
// }
// return dynInv;
//}
} }
} }

152
SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs

@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class MemberConstExpressionResolve : BaseResolve
{
public MemberConstExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
var expression = base.Expression as MemberExpression;
var isLeft = parameter.IsLeft;
var isSingle = parameter.Context.IsSingle;
object value = GetValue(expression.Member, 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 = expression.Expression.GetType()
}));
}
if (isLeft == null && base.Context.SqlWhere == null)
{
base.Context.SqlWhere = new StringBuilder();
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;
{
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;
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;
}
}
}

16
SqlSugar/ExpressionsToSql/ResolveItems/MemberNewExpressionResolve.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class MemberNewExpressionResolve : BaseResolve
{
public MemberNewExpressionResolve(ExpressionParameter parameter) : base(parameter) {
}
}
}

2
SqlSugar/SqlSugar.csproj

@ -99,6 +99,8 @@
<Compile Include="Entities\DbTableInfo.cs" /> <Compile Include="Entities\DbTableInfo.cs" />
<Compile Include="ExpressionsToSql\BinaryExpressionInfo.cs" /> <Compile Include="ExpressionsToSql\BinaryExpressionInfo.cs" />
<Compile Include="ExpressionsToSql\ExpressionErrorMessage.cs" /> <Compile Include="ExpressionsToSql\ExpressionErrorMessage.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\MemberConstExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\MemberNewExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\SugarParameter.cs" /> <Compile Include="ExpressionsToSql\SugarParameter.cs" />
<Compile Include="ExpressionsToSql\ExpressionParameter.cs" /> <Compile Include="ExpressionsToSql\ExpressionParameter.cs" />
<Compile Include="Entities\JoinQueryInfo.cs" /> <Compile Include="Entities\JoinQueryInfo.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