protected override Expression OnBuild(ExpressionBuilderContext <ExpressionOptimizerState> context) { if (context.State.Hits <= 1) { return(context.Expression); } if (context.State.Index++ == 0) { ParameterExpression variable = context.State.Variable = Expression.Variable(context.Expression.Type); context.Variables.Add(variable); return(Expression.Assign(variable, context.Expression)); } return(context.State.Variable); }
private Expression ScanHandler(Expression expression) { if (this.idMap.TryGetValue(expression, out object key)) { ExpressionBuilderContext <TState> context = new ExpressionBuilderContext <TState>() { Key = key, Batch = this.exprMap[key], Expression = expression, State = this.stateMap[key], Variables = new List <ParameterExpression>(), }; this.OnScan(context); } return(expression); }
private Expression BuildHandler(Expression expression) { if (this.idMap.TryGetValue(expression, out object key)) { ExpressionBuilderContext <TState> context = new ExpressionBuilderContext <TState>() { Key = key, Batch = this.exprMap[key], Expression = expression, State = this.stateMap[key], Variables = new List <ParameterExpression>(), }; Expression result = this.OnBuild(context); this.variables.AddRange(context.Variables); return(result); } return(expression); }
protected abstract Expression OnBuild(ExpressionBuilderContext <TState> context);
protected abstract void OnScan(ExpressionBuilderContext <TState> context);
protected override void OnScan(ExpressionBuilderContext <ExpressionOptimizerState> context) { context.State.Hits++; }