Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 protected abstract Expression OnBuild(ExpressionBuilderContext <TState> context);
Ejemplo n.º 5
0
 protected abstract void OnScan(ExpressionBuilderContext <TState> context);
Ejemplo n.º 6
0
 protected override void OnScan(ExpressionBuilderContext <ExpressionOptimizerState> context)
 {
     context.State.Hits++;
 }