protected virtual void VisitConstant(ConstantExpression c, SqlVistorFlag flag) { var value = c.Value ?? "null"; if (flag.is_right) { var paraName = GetCustomParaName(flag.para_pretoken); // flag.GetCustomParaName(); flag.Append(paraName, true); if (c.Type.IsEnum) { AddParameter(paraName, (int)c.Value); } else if (c.Type == typeof(bool)) { AddParameter(paraName, (bool)value ? 1 : 0); } else { AddParameter(paraName, value); } } else { flag.Append(value.ToString()); } }
private void MethodCallLike(MethodCallExpression exp, SqlVistorFlag flag) { Visit(exp.Object, flag); flag.Append(GetUnaryOperater(flag.unary_type)); flag.Append(" LIKE CONCAT('%',"); VisitRight(exp.Arguments[0], flag); flag.Append(",'%')"); }
protected virtual void VisitMember(MemberExpression exp, SqlVistorFlag flag) { if (exp.Expression != null && exp.Expression.NodeType == ExpressionType.Parameter) { if (flag.is_right && flag.vistor_type == SqlVistorType.Update) { var proParaName = flag.GetParaName(exp.Member.Name); flag.Append(proParaName, true); AddMemberProperty(proParaName, exp.Member.Name); } else { if (exp.Member.DeclaringType.GetTypeInfo().IsGenericType && exp.Member.DeclaringType?.GetGenericTypeDefinition() == typeof(Nullable <>)) { if (exp.Member.Name == "Value") { Visit(exp.Expression, flag); } if (exp.Member.Name != "HasValue") { return; } var doesNotEqualNull = Expression.MakeBinary(ExpressionType.NotEqual, exp.Expression, Expression.Constant(null)); Visit(doesNotEqualNull, flag); } else { flag.Append(flag.GetColName(exp.Member.Name), true); } } } else { var value = Expression.Lambda(exp).Compile().DynamicInvoke(); Visit(Expression.Constant(value), flag); } }
protected virtual void VisitNew(NewExpression nex, SqlVistorFlag flag) { for (var i = 0; i < nex.Members.Count; i++) { var arg = nex.Arguments[i]; var member = nex.Members[i]; flag.Append(flag.GetColName(member.Name)).Append("="); VisitRight(arg, flag); } }
protected virtual void VisitBinary(BinaryExpression exp, SqlVistorFlag flag) { var operand = GetBinaryOperater(exp.NodeType); if (exp.NodeType == ExpressionType.AndAlso || exp.NodeType == ExpressionType.OrElse) { flag.Append("("); Visit(exp.Left, flag); flag.Append(") ").Append(operand).Append(" ("); Visit(exp.Right, flag); flag.Append(")"); } else { Visit(exp.Left, flag); flag.Append(operand); VisitRight(exp.Right, flag); } }