public static IAggregateExpression CompileAggregateExpression(NamedExpressionElement element, IEnumerable <Declaration> declarations) { var declarationsList = declarations.ToList(); if (element.Imports.Count() == 1 && Equals(element.Imports.Single(), declarationsList.Last())) { var optimizer = new ExpressionSingleParameterOptimizer <Func <object, object> >(); var optimizedExpression = optimizer.ConvertParameter(element.Expression); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, element.Expression.Parameters.Count); var expression = new AggregateFactExpression(element.Name, element.Expression, fastDelegate); return(expression); } else { var optimizer = new ExpressionMultiParameterOptimizer <Func <object[], object> >(); var optimizedExpression = optimizer.CompactParameters(element.Expression, 0); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, element.Expression.Parameters.Count); var factMap = IndexMap.CreateMap(element.Imports, declarationsList); var expression = new AggregateExpression(element.Name, element.Expression, fastDelegate, factMap); return(expression); } }
public static FastDelegate <Action <IContext, object[]> > Action(LambdaExpression expression) { var optimizer = new ExpressionMultiParameterOptimizer <Action <IContext, object[]> >(); var optimizedExpression = optimizer.CompactParameters(expression, 1); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, expression.Parameters.Count - 1); return(fastDelegate); }
public static FastDelegate <Func <object[], bool> > BetaCondition(LambdaExpression expression) { var optimizer = new ExpressionMultiParameterOptimizer <Func <object[], bool> >(); var optimizedExpression = optimizer.CompactParameters(expression, 0); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, expression.Parameters.Count); return(fastDelegate); }
public static IActivationCondition CompileFilterCondition(FilterElement element, IEnumerable <Declaration> declarations) { var optimizer = new ExpressionMultiParameterOptimizer <Func <object[], bool> >(); var optimizedExpression = optimizer.CompactParameters(element.Expression, 0); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, element.Expression.Parameters.Count); var factMap = IndexMap.CreateMap(element.Imports, declarations); var expression = new ActivationCondition(element.Expression, fastDelegate, factMap); return(expression); }
public static IBindingExpression CompileBindingExpression(BindingElement element, IEnumerable <Declaration> declarations) { var optimizer = new ExpressionMultiParameterOptimizer <Func <object[], object> >(); var optimizedExpression = optimizer.CompactParameters(element.Expression, 0); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, element.Expression.Parameters.Count); var factMap = IndexMap.CreateMap(element.References, declarations); var expression = new BindingExpression(element.Expression, fastDelegate, factMap); return(expression); }
public static IRuleAction CompileAction(ActionElement element, IEnumerable <Declaration> declarations, IEnumerable <Declaration> dependencies) { var optimizer = new ExpressionMultiParameterOptimizer <Action <IContext, object[]> >(); var optimizedExpression = optimizer.CompactParameters(element.Expression, 1); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, element.Expression.Parameters.Count - 1); var tupleFactMap = IndexMap.CreateMap(element.Imports, declarations); var dependencyIndexMap = IndexMap.CreateMap(element.Imports, dependencies); var action = new RuleAction(element.Expression, fastDelegate, tupleFactMap, dependencyIndexMap, element.ActionTrigger); return(action); }