public AlphaBuilderContext <T> BuildSelectionNode <T>(AlphaBuilderContext <T> context, Expression <Func <T, bool> > conditionExpression) where T : class { using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>")) { var alphaCondition = new AlphaCondition <T>(conditionExpression); _logger.LogDebug($"Condition: {alphaCondition}"); IAlphaNode <T> alphaNode = context.CurrentNode; SelectionNode <T> selectionNode = alphaNode.GetChildNodes <SelectionNode <T> >() .FirstOrDefault(x => x.Condition.Equals(alphaCondition)); if (selectionNode == null) { using (_logger.BeginScope("Create")) { _logger.LogDebug($"Creating selection node: {typeof(T).Name}"); selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition); alphaNode.AddChild(selectionNode); } } return(new RuntimeAlphaBuilderContext <T>(context.Declaration, selectionNode)); } }
public ISelectionNode <T> BuildSelectionNode <T>(BuilderContext context, Expression <Func <T, bool> > conditionExpression) where T : class { using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>")) { var alphaCondition = new AlphaCondition <T>(conditionExpression); _logger.LogDebug($"Condition: {alphaCondition}"); if (context.CurrentAlphaNode == null) { throw new RuntimeBuilderException("CurrentAlphaNode must not be null"); } var selectionNode = context.CurrentAlphaNode.GetChildNodes <SelectionNode <T> >() .FirstOrDefault(x => x.Condition.Equals(alphaCondition)); if (selectionNode == null) { using (_logger.BeginScope("Create")) { selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition); context.CurrentAlphaNode.AddChild(selectionNode); } } context.CurrentAlphaNode = selectionNode; return(selectionNode); } }
public ISelectionNode <T> BuildSelectionNode <T>(BuilderContext context, Expression <Func <T, bool> > conditionExpression) where T : class { using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>")) { var alphaCondition = new AlphaCondition <T>(conditionExpression); _logger.LogDebug($"Condition: {alphaCondition}"); var alphaNode = context.CurrentAlphaNode ?? BuildTypeNode <T>(context); SelectionNode <T> selectionNode = alphaNode.GetChildNodes <SelectionNode <T> >() .FirstOrDefault(x => x.Condition.Equals(alphaCondition)); if (selectionNode == null) { using (_logger.BeginScope("Create")) { _logger.LogDebug($"Creating selection node: {typeof(T).Name}"); selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition); alphaNode.AddChild(selectionNode); } } context.CurrentAlphaNode = selectionNode; context.AlphaSource = selectionNode.MemoryNode; return(selectionNode); } }
public static IAlphaCondition CompileAlphaCondition(ConditionElement element) { var optimizer = new ExpressionSingleParameterOptimizer <Func <object, bool> >(); var optimizedExpression = optimizer.ConvertParameter(element.Expression); var @delegate = optimizedExpression.Compile(); var fastDelegate = Create(@delegate, element.Expression.Parameters.Count); var condition = new AlphaCondition(element.Expression, fastDelegate); return(condition); }