예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 protected abstract Expression OnBuild(ExpressionBuilderContext <TState> context);
예제 #5
0
 protected abstract void OnScan(ExpressionBuilderContext <TState> context);
예제 #6
0
 protected override void OnScan(ExpressionBuilderContext <ExpressionOptimizerState> context)
 {
     context.State.Hits++;
 }