Skip to content

Commit

Permalink
- 优化 ToList 针对 bool 自动转成 CASE When;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 12, 2024
1 parent 18b8613 commit cb10351
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,22 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
for (var a = 0; a < initExp.NewExpression.Arguments.Count; a++)
{
var initExpArg = initExp.NewExpression.Arguments[a];
if (initExpArg.Type == typeof(bool) && initExpArg.NodeType == ExpressionType.Call)
initExpArg = Expression.Condition(initExpArg, Expression.Constant(true, typeof(bool)), Expression.Constant(false, typeof(bool)));
if (initExpArg.Type == typeof(bool))
switch (initExpArg.NodeType)
{
case ExpressionType.Call:
case ExpressionType.OrElse:
case ExpressionType.AndAlso:
case ExpressionType.GreaterThan:
case ExpressionType.GreaterThanOrEqual:
case ExpressionType.LessThan:
case ExpressionType.LessThanOrEqual:
case ExpressionType.NotEqual:
case ExpressionType.Equal:
case ExpressionType.Not:
initExpArg = Expression.Condition(initExpArg, Expression.Constant(true, typeof(bool)), Expression.Constant(false, typeof(bool)));
break;
}
var child = new ReadAnonymousTypeInfo
{
Property = null,
Expand Down Expand Up @@ -428,8 +442,22 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
var initAssignExp = (initExp.Bindings[a] as MemberAssignment);
if (initAssignExp == null) continue;
var initExpArg = initAssignExp.Expression;
if (initExpArg.Type == typeof(bool) && initExpArg.NodeType == ExpressionType.Call)
initExpArg = Expression.Condition(initExpArg, Expression.Constant(true, typeof(bool)), Expression.Constant(false, typeof(bool)));
if (initExpArg.Type == typeof(bool))
switch (initExpArg.NodeType)
{
case ExpressionType.Call:
case ExpressionType.OrElse:
case ExpressionType.AndAlso:
case ExpressionType.GreaterThan:
case ExpressionType.GreaterThanOrEqual:
case ExpressionType.LessThan:
case ExpressionType.LessThanOrEqual:
case ExpressionType.NotEqual:
case ExpressionType.Equal:
case ExpressionType.Not:
initExpArg = Expression.Condition(initExpArg, Expression.Constant(true, typeof(bool)), Expression.Constant(false, typeof(bool)));
break;
}
var child = new ReadAnonymousTypeInfo
{
Property = initExp.Type.GetProperty(initExp.Bindings[a].Member.Name, BindingFlags.Public | BindingFlags.Instance), //#427 不能使用 BindingFlags.IgnoreCase
Expand Down Expand Up @@ -465,8 +493,22 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
for (var a = 0; a < newExp.Arguments.Count; a++)
{
var initExpArg = newExp.Arguments[a];
if (initExpArg.Type == typeof(bool) && initExpArg.NodeType == ExpressionType.Call)
initExpArg = Expression.Condition(initExpArg, Expression.Constant(true, typeof(bool)), Expression.Constant(false, typeof(bool)));
if (initExpArg.Type == typeof(bool))
switch (initExpArg.NodeType)
{
case ExpressionType.Call:
case ExpressionType.OrElse:
case ExpressionType.AndAlso:
case ExpressionType.GreaterThan:
case ExpressionType.GreaterThanOrEqual:
case ExpressionType.LessThan:
case ExpressionType.LessThanOrEqual:
case ExpressionType.NotEqual:
case ExpressionType.Equal:
case ExpressionType.Not:
initExpArg = Expression.Condition(initExpArg, Expression.Constant(true, typeof(bool)), Expression.Constant(false, typeof(bool)));
break;
}
var csname = newExp.Members != null ? newExp.Members[a].Name : (initExpArg as MemberExpression)?.Member.Name;
var child = new ReadAnonymousTypeInfo
{
Expand Down

0 comments on commit cb10351

Please sign in to comment.