protected override Expression VisitMethodCall(MethodCallExpression node) { var result = new FunctionExpressionResovle(node).Resovle(); _textBuilder.Append($"{result} AS expr"); return(node); }
protected override Expression VisitNew(NewExpression node) { for (int i = 0; i < node.Arguments.Count; i++) { var item = node.Arguments[i]; var column = node.Members[i].Name; if (item is MemberExpression member) { var name = TableInfoCache .GetColumnName(member.Member.DeclaringType, member.Member.Name); if (name != column) { _textBuilder.Append($"{name} AS {column}"); } else { _textBuilder.Append($"{name}"); } } else if (item is MethodCallExpression) { var expression = new FunctionExpressionResovle(item).Resovle(); _textBuilder.Append($"{expression} AS {column}"); } if (i != node.Arguments.Count - 1) { _textBuilder.Append(","); } } return(node); }
protected override Expression VisitMethodCall(MethodCallExpression node) { if (node.Method.DeclaringType == typeof(Operator)) { if (node.Arguments.Count == 2) { _textBuilder.Append("("); SetParameterName(node.Arguments[0] as MemberExpression); var type = Operator.ResovleExpressionType(node.Method.Name); _textBuilder.Append($" {type} "); var value = VisitConstantValue(node.Arguments[1]); if (node.Method.Name == nameof(Operator.StartsWith) || node.Method.Name == nameof(Operator.NotStartsWith)) { SetParameterValue(Expression.Constant($"{value}%", typeof(string))); } else if (node.Method.Name == nameof(Operator.EndsWith) || node.Method.Name == nameof(Operator.NotEndsWith)) { SetParameterValue(Expression.Constant($"%{value}", typeof(string))); } else if (node.Method.Name == nameof(Operator.Contains) || node.Method.Name == nameof(Operator.NotContains)) { SetParameterValue(Expression.Constant($"%{value}%", typeof(string))); } else { SetParameterValue(Expression.Constant(value)); } _textBuilder.Append(")"); } } else if (node.Method.DeclaringType.GetCustomAttribute(typeof(FunctionAttribute), true) != null) { var function = new FunctionExpressionResovle(node).Resovle(); _textBuilder.Append(function); } else { SetParameterValue(node); } return(node); }
protected override Expression VisitMemberInit(MemberInitExpression node) { for (int i = 0; i < node.Bindings.Count; i++) { var item = node.Bindings[i] as MemberAssignment; if (item.Expression is MemberExpression member) { var name = TableInfoCache .GetColumnName(member.Member.DeclaringType, member.Member.Name); _textBuilder.Append($"{name} AS {item.Member.Name}"); } else if (item.Expression is MethodCallExpression) { var expression = new FunctionExpressionResovle(item.Expression).Resovle(); _textBuilder.Append($"{expression} AS {item.Member.Name}"); } if (i != node.Bindings.Count - 1) { _textBuilder.Append(","); } } return(node); }