using Connected.Expressions.Visitors; using System.Linq.Expressions; namespace Connected.Expressions.Translation.Rewriters; public class ParameterRewriter : DatabaseVisitor { private ParameterRewriter(ExpressionCompilationContext context) { Context = context; } private ExpressionCompilationContext Context { get; } public static Expression Rewrite(ExpressionCompilationContext context, Expression expression) { return new ParameterRewriter(context).Visit(expression); } protected override Expression VisitBinary(BinaryExpression expression) { return base.VisitBinary(expression); } protected override Expression VisitConstant(ConstantExpression expression) { var parameter = Context.Parameters.FirstOrDefault(f => f.Value == expression); if (parameter.Value is not null) return Expression.Constant($"@{parameter.Key}"); return base.VisitConstant(expression); } }